xt_pknock: import digest generation utility

This commit is contained in:
Jan Engelhardt
2016-04-22 22:48:56 +02:00
parent bc6aaf74d8
commit 80bed0655f
2 changed files with 32 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
from Crypto.Hash import SHA256
from Crypto.Hash import MD5
import sys
import hmac
import struct
import socket
from time import time
def gen_hmac(secret, ip):
epoch_mins = (long)(time()/60)
s = hmac.HMAC(secret, digestmod = SHA256)
s.update(socket.inet_aton(socket.gethostbyname(ip)))
s.update(struct.pack("i", epoch_mins)) # "i" is for integer
print s.hexdigest()
if __name__ == '__main__':
gen_hmac(sys.argv[1], sys.argv[2])

15
extensions/pknock/knock.sh Executable file
View File

@@ -0,0 +1,15 @@
#!/bin/bash
# $1 -> IP src
# $2 -> IP dst
# $3 -> PORT dst
# $4 -> secret
if [ -z $4 ]; then
echo "usage: $0 <IP src> <IP dst> <PORT dst> <secret>"
exit 1
fi
digest_file="/tmp/digest.txt"
python ../test/py/gen_hmac.py $4 $1 > $digest_file
nemesis udp -S $1 -D $2 -y $3 -P $digest_file