forked from trustedsec/artillery
-
Notifications
You must be signed in to change notification settings - Fork 197
/
remove_ban.py
executable file
·43 lines (38 loc) · 1.42 KB
/
remove_ban.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
#!/usr/bin/python
#
# simple remove banned ip
#
#
import sys
from src.core import *
try:
ipaddress = sys.argv[1]
if is_valid_ipv4(ipaddress):
path = check_banlist_path()
fileopen = file(path, "r")
data = fileopen.read()
data = data.replace(ipaddress + "\n", "")
filewrite = file(path, "w")
filewrite.write(data)
filewrite.close()
print("Listing all iptables looking for a match... if there is a massive amount of blocked IP's this could take a few minutes..")
proc = subprocess.Popen("iptables -L ARTILLERY -n -v --line-numbers | grep %s" % (
ipaddress), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
for line in proc.stdout.readlines():
line = str(line)
match = re.search(ipaddress, line)
if match:
# this is the rule number
line = line.split(" ")
line = line[0]
print(line)
# delete it
subprocess.Popen("iptables -D ARTILLERY %s" % (line),
stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
# if not valid then flag
else:
print("[!] Not a valid IP Address. Exiting.")
sys.exit()
except IndexError:
print("Description: Simple removal of IP address from banned sites.")
print("[!] Usage: remove_ban.py <ip_address_to_ban>")