-
Notifications
You must be signed in to change notification settings - Fork 2
/
rubberpant.py
198 lines (166 loc) · 6.71 KB
/
rubberpant.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
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
import requests
import json
import sys
from progress.bar import Bar
import os, platform
from argparse import ArgumentParser
from colorama import Fore, Back, Style
import threading
verbose = False
check = False
os_env = platform.platform()
def clear_screen(os_env):
if 'Windows' in os_env:
os.system('cls')
else:
os.system('clear')
def _start():
banner = '''
______ _ _ ______ _
| ___ \ | | | | | ___ \ | |
| |_/ _ _| |__ | |__ ___ _ __| |_/ __ _ _ __ | |_
| | | | | '_ \| '_ \ / _ | '__| __/ _` | '_ \| __|
| |\ | |_| | |_) | |_) | __| | | | | (_| | | | | |_
\_| \_\__,_|_.__/|_.__/ \___|_| \_| \__,_|_| |_|\__|
'''+Fore.RED+'''Version: 1.0
Author: @mztique et. @eeyitemi
Github: @dipman467
'''+Style.RESET_ALL
print(banner)
def get_args():
parser = ArgumentParser()
parser.add_argument('-c','--check', help='Only check if your IP is exposed or not', required=False, action='store_true')
parser.add_argument('-ip','--ip', help='Work on a single IP Address', required=False)
parser.add_argument('-p','--port', help='port to check [default:9200]', required=False)
parser.add_argument('-n','--cidr', help='Work on a CIDR Notation of /24', required=False)
parser.add_argument('-f','--file', help='Work on a list of IP address', required=False)
parser.add_argument('-r','--range', help='Work on an IP range',required=False)
#parser.add_argument('-t','--thread', help='Number of threads to use [only use with -c or --check]',required=False)
parser.add_argument('-v','--verbose', help='Read output to terminal',required=False, action='store_true')
return parser.parse_args()
def ip_range(ip,port):
try:
start, stop = ip.split("-")
_start = start.split(".")
_stop = stop.split(".")
#Check same subnet
if _start[2] == _stop[2]:
start_host_index = int(_start[3])
stop_host_index = int(_stop[3])
counter = start_host_index
while stop_host_index != counter-1:
ip_address = _start[0]+"."+_start[1]+"."+_start[2]+"."+str(counter)
host = ip_address+":"+port
print(Fore.GREEN+"Checking ===> {}".format(host)+Style.RESET_ALL)
elastic_rubber(host)
counter = counter + 1
except Exception as ex:
print("[IPRange]Error Occured! {}, please check and try again".format(ex))
def cidr(ip,port):
try:
#TODO calculate cidr notation
ip,cidr = ip.split("/")
if cidr == "24":
start = ip.split(".")
for i in range(255):
ip_address = start[0]+"."+start[1]+"."+start[2]+"."+str(i)
host = ip_address+":"+port
print(Fore.GREEN+"Checking ===> {}".format(host)+Style.RESET_ALL)
elastic_rubber(host)
else:
print("Sorry only /24 notation supported")
except Exception as e:
print("[CIDR]Error Occured! {}, please check and try again".format(e))
def ipfile(infile):
try:
with open(infile,'r+') as file:
for ip in file.readlines():
host = ip.strip("\n")+":"+port
print(Fore.GREEN+"Checking ===> {}".format(host)+Style.RESET_ALL)
elastic_rubber(host)
except Exception as e:
print("[IPFile]Error Occured! {}, please check and try again".format(e))
def elastic_rubber(host):
try:
#Check host
elastic = requests.get("http://"+host)
if elastic.status_code == 200:
if "cluster_name" in elastic.text:
if check:
print(Fore.GREEN+host+"\tEXPOSED"+Style.RESET_ALL)
return
elastic_host = json.loads(elastic.text)
print(json.dumps(elastic_host, indent=4))
index_cmd = "/_cat/indices/?v&pretty"
indices = requests.get("http://"+host+index_cmd)
print(indices.text)
if "index" in indices.text:
index = input("What index do you wish to explore? ")
explore_index(host,index)
else:
print("Sorry! Index not found. Ensure the name is written correctly")
else:
if check:
print(Fore.RED+host+"\tNOT EXPOSED"+Style.RESET_ALL)
else:
print("{}: Cluster name not found. Ensure it's an Elasticsearch instance".format(host))
else:
print("No Elasticsearch instance found")
except Exception as ex:
print("[Main]Error Occured! {} or Not an elasticsearch instance, please check and try again".format(ex))
def explore_index(host,index):
_size = input("How many data set to explore? ")
_from = input("Where to start downloading?[default:0] ")
if not _from:
_from = '0'
print()
explore_cmd = "/_search/?q=*&size="+_size+"&from="+_from
re = requests.get("http://"+host+"/"+index+explore_cmd)
data = json.loads(re.text)
if int(data["hits"]["total"]) > 0:
hits = data["hits"]["hits"]
#_host = host.replace(".","_")
_host = host.replace(":","-")
filename = _host+'_'+index+'.txt'
f = open(filename, 'a+')
bar = Bar('Downloading', max=len(hits))
for i in hits:
source = dict(i)
_source = source["_source"]
f.writelines(json.dumps(_source, indent=4))
if verbose:
#Color the lines if possible
print(json.dumps(_source, indent=4))
else:
bar.next()
if not verbose: bar.finish()
print("Results saved to: {}".format(filename))
else:
print("Nothing found, see below\n{}".format(data))
if __name__ == '__main__':
clear_screen(os_env)
_start()
args = get_args()
port = args.port if args.port else "9200"
#Assign all args
check = args.check
ip = args.ip
cider = args.cidr
iprange = args.range
infile = args.file
verbose = args.verbose
if check:
check = True
if verbose:
verbose = True
if infile:
ipfile(infile)
elif ip:
host = str(ip) + ":" + str(port)
elastic_rubber(host)
elif cider:
cidr(cider,port)
elif iprange:
ip_range(iprange,port)
else:
print("You need to specify one method of IP addressing. Type -h or --help for usage help")