-
Notifications
You must be signed in to change notification settings - Fork 0
/
dnxsvr.nim
38 lines (33 loc) · 1.07 KB
/
dnxsvr.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import std/[net, strutils, asyncnet, asyncdispatch, sha1]
import zippy
let withSize = 256
var socket = newAsyncSocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
socket.bindAddr(port = Port 53)
echo "[+] Listening..."
var
query: string
name: string
while true:
let
req = waitfor socket.recvFrom(withSize)
data = $req.data
x = data.toHex[26 .. ^1]
#echo "[DEBUG] ", x
if x.contains("71756974"):
break
elif x.contains("02626211"):
#echo "[DEBUG] ", parseHexStr(x[0 .. ^61])
name.add(parseHexStr(x[0 .. ^61]))
elif x.contains("016103"):
#echo "[DEBUG] ", parseHexStr(x[0 .. ^61])
query.add(parseHexStr(x[0 .. ^61]))
try:
let
gz = parseHexStr(query)
filename = parseHexStr(name)
content = uncompress(gz, dfGzip)
hash = secureHash(content)
writeFile($hash & "_" & filename, content)
echo "[+] Received: ", filename, " [lengh: ", content.len, "][hash: ", hash, "]"
except CatchableError as e:
echo "[!] Error: ", e.msg