| 1 | // domain data encoding/decoding algo for FrameworkPOS Malware DNS-Tunneling Variant, |
| 2 | // as described on: |
| 3 | // https://blog.gdata.de/artikel/neue-variante-von-frameworkpos-schoepft-daten-ueber-dns-anfragen-ab/ |
| 4 | // |
| 5 | |
| 6 | package main |
| 7 | |
| 8 | import( |
| 9 | "fmt" |
| 10 | "os" |
| 11 | "encoding/hex" |
| 12 | "flag" |
| 13 | ) |
| 14 | |
| 15 | const A = 0xAA |
| 16 | const B = 0x9B |
| 17 | const C = 0xC3 |
| 18 | |
| 19 | var op string |
| 20 | var in string |
| 21 | |
| 22 | func init(){ |
| 23 | flag.StringVar(&op, "op", "decode", "operation to perform: 'encode' or 'decode', default is 'decode'") |
| 24 | flag.StringVar(&in, "in", "", "Inputstring to perform choosen operation on") |
| 25 | } |
| 26 | |
| 27 | // decode - decodes single values from dns queries into cleartext |
| 28 | func decode(data []byte)(result []byte){ |
| 29 | for _, v := range data { |
| 30 | a := v ^ A |
| 31 | b := a ^ B |
| 32 | result = append(result, b ^ C) |
| 33 | } |
| 34 | return result |
| 35 | } |
| 36 | |
| 37 | // encode - encodes cleartext values to be used in dns queries |
| 38 | func encode(data []byte)(result []byte) { |
| 39 | for _, v := range data { |
| 40 | b := v ^ C |
| 41 | a := b ^ B |
| 42 | result = append(result, a ^ A) |
| 43 | } |
| 44 | return result |
| 45 | } |
| 46 | |
| 47 | func main(){ |
| 48 | flag.Parse() |
| 49 | input := []byte(in) |
| 50 | |
| 51 | switch { |
| 52 | case op == "encode": |
| 53 | encoded := encode(input) |
| 54 | fmt.Printf("%s %x\n", input, string(encoded)) |
| 55 | case op == "decode": |
| 56 | data, err := hex.DecodeString(string(input)) |
| 57 | if err != nil { |
| 58 | panic(err) |
| 59 | } |
| 60 | decoded := decode(data) |
| 61 | fmt.Printf("%x %s\n", data, string(decoded)) |
| 62 | default: |
| 63 | prog := os.Args[0] |
| 64 | fmt.Printf("For USAGE INFO call: '%s -h'\n", prog) |
| 65 | } |
| 66 | } |
scusi / dns_xor.go
Last active 6 months ago
Revision c4034de8f65288d79d8ffe40fd057b6dc20df0a6