-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
138 lines (130 loc) · 4.68 KB
/
config.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
#SchorchedVenom
#10/24/2019
#
#Based on Reddit request on r/AskNetsec
#
#!/usr/bin/python3
#
#Libraries
import os
import subprocess
import socket
import array as arr
#Variables
global fileOutputFile
global portNumbers
global ipAddressCount
global ipAddress
global configFile
global diffOutputFile
#Config Creation
configFile = open("config.txt", "w")
#User Interaction
os.system('clear')
print("Welcome to the 1 time configuration script!")
fileOutputFile = input("Please enter the desired name for your output file: ")
print("fileOutput={}".format(fileOutputFile),file=configFile)
diffOutputFile = input("Please enter the desired name for you diff output file: ")
print("diffOutput={}".format(diffOutputFile),file=configFile)
os.system('clear')
x = 0
portArray = arr.array('i')
while x == 0:
response = input("Which Port Numbers Would You Like To Scan?\n1.1-1023 \n2.1-65535 \n3.Enter your own port numbers \nPlease Choose one of the above: ")
if response == "1":
port = 1
while port < 1024:
portArray.append(int(port))
port += 1
portList = portArray.tolist()
print("portNumbers={}".format(portList),file=configFile)
x = 1
elif response == "2":
port = 1
while port < 65536:
portArray.append(int(port))
port += 1
portList = portArray.tolist()
print("portNumbers={}".format(portList),file=configFile)
x = 1
elif response == "3":
os.system('clear')
port = ""
while port != "exit" or port != "Exit":
os.system('clear')
port = input("Please enter a port to scan or enter Exit to finish: ")
if port != "exit" or port != "Exit":
portArray.append(int(port))
else:
portList = portArray.tolist()
print("portNumbers={}".format(portList),file=configFile)
x = 1
else:
os.system('clear')
input("Invalid response, press enter to try again!")
#Ip Address Count
os.system('clear')
ipArray = []
print("Would you like to scan more than 1 IP Address?")
x = 0
while x == 0:
response = input("1.Yes\n2.No\nPlease enter a choice: ")
if response == "1" or response == "yes" or response == "Yes":
ipAddress = ""
print("ipAddressCount=Yes")
while ipAddress != "99":
os.system('clear')
ipAddress = input("Please enter a IP to scan or enter 99 to finish: ")
if ipAddress != "99":
ipArray.append(str(ipAddress))
else:
ipFile = open("ipaddress.txt", "w")
print("ipAddress={}".format(ipArray),file=ipFile)
x = 1
ipFile.close()
elif response == "2" or response == "no" or response == "No":
ipAddress = input("Please enter your target IP Address: ")
print("ipAddress={}".format(ipAddress),file=configFile)
x = 1
else:
input("Invalid Response! Please press enter to try again!")
configFile.close()
fileOutput = open(fileOutputFile,"w")
#Run Port Map
socket.setdefaulttimeout(10)
for i in ipAddress:
print ("------{}------".format(i),file=fileOutput)
targetServer = socket.gethostbyname(i)
for port in portList:
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
result = sock.connect_ex((targetServer,port))
if result == 0:
print("Port:{} Open".format(port),file=fileOutput)
sock.close()
banner = ""
if port == 80 or port == 8080 or port == 443 or port == 4434:
sock = socket.socket()
sock.connect((targetServer,port))
sock.send(b'HEAD /\n\n')
banner = sock.recv(1024)
else:
sock = socket.socket()
sock.connect((targetServer,port))
banner = sock.recv(1024)
print("Port:{} ".format(port) + "Banner:{} ".format(banner),file=fileOutput)
sock.close()
fileOutput.close()
#Create Initial scan file
outPutTransfer = [line.rstrip('\n') for line in open("./{}".format(fileOutputFile))]
initOutput = open("init_scan.txt", "w")
for line in outPutTransfer:
print("{}".format(i),file=initOutput)
initOutput.close()
#Create Cronfile
currentDirectory = os.getcwd()
pythonCommand = "@hourly python3 " + str(currentDirectory) + "/PortChecker.py"
cronCommand = "crontab " + str(currentDirectory) + "/PortCheckerCron"
cronFile = open("PortCheckerCron", "w")
print("{}".format(pythonCommand),file=cronFile)
cronFile.close()
os.system(str(cronCommand))