-
Notifications
You must be signed in to change notification settings - Fork 1
/
Hackbot.py
330 lines (320 loc) · 35.8 KB
/
Hackbot.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
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
#!/usr/bin/python
import time
import subprocess
import telepot
import os
import urllib2
import re
import json
import datetime
import requests
import threading
import wikipedia
from bs4 import BeautifulSoup
from urllib2 import urlopen
import youtube_dl
def handle(msg):
chat_id = msg['chat']['id']
command = msg['text']
print "Got Command : %s " %command
bot.sendMessage(chat_id,'\xF0\x9F\x98\x81 Welcome to -+ HackBot v1.2 +- (https://goo.gl/mxQ4Sv) \xE2\x9C\x94')
#welcome screen and help
if command.startswith('help') or command.startswith('/start'):
bot.sendMessage(chat_id,'\xF0\x9F\x98\x9A HELP MENU: ')
bot.sendMessage(chat_id,'1. Run built-in tools : example -> nmap -sV site.com')
bot.sendMessage(chat_id,'2. Give Foldername and Command : example -> tool foldername python scriptname.py\n')
bot.sendMessage(chat_id,'3. BTC Rate : example -> btc usd or btc anycurrency')
bot.sendMessage(chat_id,'4. Hackerone Disclosed Bugs : usage : h1bugs')
bot.sendMessage(chat_id,'5. Get Tweets of any search and times : usage : tweet bugbounty 5 or tweet motivation 3')
bot.sendMessage(chat_id,'6. Get details of HackerOne disclosed report: usage: #152407 \n A # sign followed by the report number')
bot.sendMessage(chat_id,'7. Hackerone Disclosed Bugs for specific program: usage: h1bugs programname')
bot.sendMessage(chat_id,'8. Get automatically notified about latest HackerOne Disclosure: usage: notifyh1')
bot.sendMessage(chat_id,'9. Search Wikipedia. usage: wiki yourtiopic')
bot.sendMessage(chat_id,'10. Get YouTube videos delivered right to your box in mp3 format: usage: yt musicname')
bot.sendMessage(chat_id,'11. Get motivated every hour. Just text -> motivateme')
return 0
#end welcome
#automatic hackerone notifier
def notifyh1():
site = requests.get('https://hackerone.com/hacktivity.json?sort_type=latest_disclosable_activity_at&filter=type%3Apublic')
json_data = json.loads(site.text)
rep_id = json_data['reports'][0]['id']
rep_str = str(rep_id)
with open('latest.txt', 'r') as rmf:
data = rmf.read().replace('\n', '')
if data != rep_str:
with open('latest.txt', 'w') as wmf:
wmf.write("%s" % rep_str)
bot.sendMessage(chat_id,"\xF0\x9F\x90\x9B New Bug Disclosed on H1 \xF0\x9F\x90\x9B")
bot.sendMessage(chat_id,"Title: "+json_data['reports'][0]['title']+" ("+json_data['reports'][0]['readable_substate']+")")
bot.sendMessage(chat_id,"https://hackerone.com"+json_data['reports'][0]['url'])
print(time.ctime())
threading.Timer(300, notifyh1).start()
if command.startswith('notifyh1') or command.startswith('Notifyh1'):
notifyh1()
return 0
#end automatic hackerone notifer
#tool
elif command.startswith('tool') or command.startswith('Tool'):
words = command.split()
mm=words[1]
cmd=words[2]+' '+words[3]
final=words[2:]
print map(str,final)
makeitastring = ' '.join(map(str, final))
print makeitastring
directory='/root/Desktop/pentest/'+str(mm)
bot.sendMessage(chat_id,"\xF0\x9F\x92\xBC your Path: "+str(directory))
if os.path.isdir(directory):
print "PATH IS OK"
try:
os.chdir(directory)
bot.sendMessage(chat_id,"\xF0\x9F\x93\x81 Changing Directory to: "+str(directory))
print "OK"
bot.sendMessage(chat_id,'\xF0\x9F\x90\x8D '+str(makeitastring))
bot.sendMessage(chat_id,'\xF0\x9F\x92\xBB [-] Wait.....[-]')
pp=subprocess.check_output(makeitastring,shell=True)
bot.sendMessage(chat_id,pp)
except ValueError as ex:
bot.sendMessage(ex,'Something')
else:
bot.sendMessage(chat_id,'Error : please check your folder path')
bot.sendMessage(chat_id,'Make sure you folder at /root/Desktop/pentest/')
return 0
#end tool
#wiki starts
elif command.startswith('wiki') or command.startswith('Wiki'):
try:
makesplit=command[5:]
print makesplit
wiksearch = wikipedia.summary(makesplit,sentences=10)
bot.sendMessage(chat_id,wiksearch+'\n'+wikipedia.page(makesplit).url)
except Exception as e:
bot.sendMessage(chat_id,'Error :'+str(e))
return 0
#wiki ends
#btc price
elif command.startswith('btc') or command.startswith('Btc'):
arg1=command[4:]
print arg1
url= "https://www.google.co.in/search?q=bitcoin+to+"+arg1
req = urllib2.Request(url, headers={'User-Agent' : "Magic Browser"})
con = urllib2.urlopen( req )
Text=con.read()
position=re.search("1 Bitcoin =",Text)
res = float(Text[position.end():position.end()+9])
axx = '1 BTC : '+str(res)+' '+arg1
bot.sendMessage(chat_id,str(axx))
return 0
#end btc price
#h1 disclosed report
elif command.startswith('h1bugs') or command.startswith('H1bugs'):
program=command[7:]
#specific program
if program:
bot.sendMessage(chat_id,'\xF0\x9F\x9A\x80 Loading HackerOne Disclosed Bugs! \xF0\x9F\x9A\x80')
bot.sendMessage(chat_id, 'Program: '+program)
site = requests.get('https://hackerone.com/hacktivity.json?filter=type%3Apublic%20to%3A'+program)
json_data = json.loads(site.text)
for i in range(10):
try:
title = "Title : "+json_data['reports'][i]['title']
url = json_data['reports'][i]['url']
urls = "Report at : https://hackerone.com/"+url
bot.sendMessage(chat_id,title)
bot.sendMessage(chat_id,urls)
print "\n"
except KeyError:
pass
#common hacktivity
else:
bot.sendMessage(chat_id,'\xF0\x9F\x9A\x80 Loading HackerOne Disclosed Bugs! \xF0\x9F\x9A\x80')
site = requests.get('https://hackerone.com/hacktivity.json?sort_type=latest_disclosable_activity_at&filter=type%3Apublic')
json_data = json.loads(site.text)
for i in range(10):
try:
title = "Title : "+json_data['reports'][i]['title']
url = json_data['reports'][i]['url']
urls = "Report at : https://hackerone.com/"+url
bot.sendMessage(chat_id,title)
bot.sendMessage(chat_id,urls)
print "\n"
except KeyError:
pass
return 0
#end h1 disclosed report.
#twitter search
elif command.startswith('tweet') or command.startswith('Tweet'):
twords=command.split()
tname=twords[1]
print tname
timetweets=twords[2]
print timetweets
turl = "https://twitter.com/search?q="+tname+"&src=typd&lang=en"
print turl
bot.sendMessage(chat_id,'\xF0\x9F\x9A\x80 Loading Tweets! \xF0\x9F\x9A\x80')
response = urllib2.urlopen(turl)
html = response.read()
soup = BeautifulSoup(html,'lxml')
tweets = soup.find_all('li','js-stream-item')
counts=0
for tweet in tweets:
if tweet.find('p','tweet-text'):
try:
tweet_user = tweet.find('span','username').text
tweet_text = tweet.find('p','tweet-text').text.encode('utf8')
tweet_id = tweet['data-item-id']
timestamp = tweet.find('a','tweet-timestamp')['title']
bot.sendMessage(chat_id,tweet_text+'\n')
counts = counts+1
print counts
print timetweets
if counts == int(timetweets):
break
else:
pass
time.sleep(1)
except UnicodeDecodeError:
pass
else:
continue
return 0
#end twitter search
#coin
elif command.startswith('coin') or command.startswith('Coin'):
res = requests.get('https://api.coinsecure.in/v1/exchange/ticker')
#print(res.text)
j = json.loads(res.text)
sell = j['message']['bid']
bot.sendMessage(chat_id,str(sell)+' INR')
return 0
#end coin
#h1 report details
elif command.startswith('#'):
repnum=command[1:]
bot.sendMessage(chat_id,'\xF0\x9F\x9A\x80 Loading report \xF0\x9F\x9A\x80')
site = requests.get('https://hackerone.com/reports/'+repnum+'.json')
json_data = json.loads(site .text)
if json_data['has_bounty?'] != 0:
bounty='Bounty: '+json_data['formatted_bounty']
replink = 'https://hackerone.com/reports/'+repnum
title = json_data['title']
username = json_data['reporter']['username']
url = json_data['reporter']['url']
state = json_data['readable_substate']
vulninfo = 'Details:\n'+json_data['vulnerability_information']
bot.sendMessage(chat_id,parse_mode='HTML',text='(<a href="'+replink+'">#'+repnum+'</a>) <b>'+title+' reported by </b><a href="https://hackerone.com'+url+'">'+username+'</a> <b>('+state+')</b>')
if json_data['has_bounty?'] != 0:
bot.sendMessage(chat_id,bounty)
bot.sendMessage(chat_id,vulninfo)
print "\n"
return 0
#end h1 report details
#motivateme
def motivation():
turl = "https://twitter.com/search?q=motivation&src=typd&lang=en"
bot.sendMessage(chat_id,'\xF0\x9F\x9A\x80 Get motivated every one hour! \xF0\x9F\x9A\x80')
response = urllib2.urlopen(turl)
html = response.read()
soup = BeautifulSoup(html,'lxml')
tweets = soup.find_all('li','js-stream-item')
counts=0
timetweets = "3"
for tweet in tweets:
if tweet.find('p','tweet-text'):
try:
tweet_user = tweet.find('span','username').text
tweet_text = tweet.find('p','tweet-text').text.encode('utf8')
tweet_id = tweet['data-item-id']
timestamp = tweet.find('a','tweet-timestamp')['title']
bot.sendMessage(chat_id,tweet_text+'\n')
counts = counts+1
if counts == int(timetweets):
break
else:
pass
time.sleep(1)
except UnicodeDecodeError:
pass
else:
continue
print(time.ctime())
threading.Timer(3600, motivation).start()
if command.startswith('motivateme') or command.startswith('Motivateme'):
motivation()
return 0
else:
print 'Nothing'
#end motivation
#youtube search
if command.startswith('yt') or command.startswith('Yt'):
param = command[3:]
response = urlopen("https://www.youtube.com/results?search_query="+param)
data = response.read()
response.close()
soup = BeautifulSoup(data,"html.parser")
vid = soup.find(attrs={'class':'yt-uix-tile-link'})
link = "https://www.youtube.com"+vid['href']
#watchid = vid['href']
#watchid = watchid.replace('/watch?v=','')
title = vid['title']
titleshorten = title[0:12]
print "Shorten Title is : "+titleshorten
print title
#print link
bot.sendMessage(chat_id,title+"\n"+link)
#bot.sendMessage(chat_id,'Audio File is on the Way , Wait....\n')
options = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '320'
}]
}
with youtube_dl.YoutubeDL(options) as ydl:
ydl.download([link])
for i,line in enumerate(os.listdir('.')):
if titleshorten in line:
thatline = line
print 'Thatline: '+thatline
bot.sendAudio(chat_id,audio=open(thatline,'rb'))
print "Sent!"
os.remove(thatline)
else:
bot.sendMessage(chat_id,'\xF0\x9F\x98\x88 [+] Got Command \xF0\x9F\x98\x88')
bot.sendMessage(chat_id,command)
bot.sendMessage(chat_id,'\xF0\x9F\x92\xBB [-] Wait.....[-]')
aa=subprocess.check_output(command,shell=True)
bot.sendMessage(chat_id,aa)
#api credentials
api = open('api.txt','r')
api_cont = api.read().strip()
bot = telepot.Bot(api_cont)
bot.message_loop(handle)
print '[+] Server is Listenining [+]'
print '[=] Type Command from Messenger [=]'
while 1:
time.sleep(10)