Skip to content

Commit 9d427db

Browse files
committed
2 parents 693ada5 + c84b5e5 commit 9d427db

9 files changed

Lines changed: 92 additions & 12 deletions

File tree

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ install:
1212
script:
1313
- python3 test_getemails.py
1414
- python3 test_getweblinks.py
15+
- python3 test_savetofile.py
1516
notifications:
1617
slack: dedsec-inside:24NHg47gypeVR3DWnEncRq7c

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
--------------------
33
All notable changes to this project will be documented in this file.
44

5+
## 1.2.0 | (Currently in Development)
6+
7+
### Added
8+
* Save to JSON
9+
* Testcase for Save to JSON
10+
511
## 1.1.0 - July 6, 2017 - Present
612

713
### Added

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ GNU Public License
129129
## CREDITS
130130

131131
- [X] [P5N4PPZ](https://github.com/PSNAppz) - Owner
132-
- [X] [agrepravin](https://github.com/agrepravin) - Contributor
132+
- [X] [agrepravin](https://github.com/agrepravin) - Contributor,Reviewer
133+
- [X] [y-mehta](https://github.com/y-mehta) - Contributer
133134

134135
![](https://upload.wikimedia.org/wikipedia/commons/thumb/4/42/Opensource.svg/200px-Opensource.svg.png)
135136

modules/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@
33
from .getweblinks import *
44
from .pagereader import *
55
from .updater import *
6+
from .savefile import *
67

7-
__all__ = (bcolors.__all__ + getemails.__all__ + getweblinks.__all__ + pagereader.__all__ + updater.__all__)
8+
9+
__all__ = (bcolors.__all__ + getemails.__all__ + getweblinks.__all__ + pagereader.__all__ + updater.__all__ + savefile.__all__ )

modules/getemails.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
import os
33
sys.path.append(os.path.abspath('../'))
44
from modules.bcolors import Bcolors
5+
from modules.savefile import saveJson
56
import bs4
67

78
__all__ = ['getMails']
89

910
"""Get all emails from the website"""
1011

11-
def getMails(soup):
12+
def getMails(soup,save=0):
1213
_soup_instance = bs4.BeautifulSoup
1314
if isinstance(type(soup), type(_soup_instance)):
1415
emails = []
@@ -27,6 +28,8 @@ def getMails(soup):
2728
print ('-------------------------------')
2829
for mail in emails:
2930
print (mail)
31+
if save:
32+
saveJson("Extracted-Mail-IDs",emails)
3033
return ''
3134
else:
3235
raise(Bcolors.FAIL+'Method parameter is not of instance bs4.BeautifulSoup'+Bcolors.ENDC)

modules/getweblinks.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sys
22
import os
33
sys.path.append(os.path.abspath('../'))
4+
from modules.savefile import saveJson
45
import urllib.request
56
from modules.bcolors import Bcolors
67
import bs4
@@ -10,23 +11,26 @@
1011

1112
__all__ = ['getLinks']
1213

13-
def link_status(web):
14+
15+
def link_status(web,out_queue,index):
1416
link_live = False
17+
out_queue[index] = web + " is_live = False "
1518
try:
1619
urllib.request.urlopen(web)
1720
link_live = True
21+
out_queue[index] = web + " is_live = True "
1822
print(web)
1923
except urllib.error.HTTPError as e:
2024
print(Bcolors.On_Red+web+Bcolors.ENDC)
2125
except urllib.error.URLError as e:
2226
print(Bcolors.On_Red+web+Bcolors.ENDC)
2327
except http.client.RemoteDisconnected as e:
2428
print(Bcolors.On_Red+web+Bcolors.ENDC)
25-
return
29+
return
2630

2731

2832
"""Get all onion links from the website"""
29-
def getLinks(soup,ext,live=0):
33+
def getLinks(soup,ext,live=0,save=0):
3034
_soup_instance = bs4.BeautifulSoup
3135
extensions = []
3236
if ext:
@@ -53,13 +57,23 @@ def getLinks(soup,ext,live=0):
5357
print ('-------------------------------')
5458
if live:
5559
threads = []
60+
result = [{} for x in websites]
5661
for web in websites:
57-
t = threading.Thread(target=link_status, args=(web,))
58-
threads.append(t)
62+
t = threading.Thread(target=link_status, args=(web,result,websites.index(web)))
5963
t.start()
64+
threads.append(t)
65+
try:
66+
for t in threads:
67+
t.join()
68+
if save:
69+
saveJson("Live-Onion-Links",result)
70+
except:
71+
pass
6072
else:
6173
for web in websites:
6274
print(web)
75+
if save:
76+
saveJson("Onion-Links",websites)
6377
return websites
6478
else:
6579
raise('Method parameter is not of instance bs4.BeautifulSoup')

modules/savefile.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import json
2+
import time
3+
4+
__all__ = ['saveJson']
5+
6+
# open the file "TorBoT-Export" in write ("a") mode
7+
def saveJson(datatype,data):
8+
"function_docstring"
9+
timestr = time.strftime("%Y%m%d-%H%M%S")
10+
#Json File Creation
11+
file = open("TorBoT-Export-"+datatype+timestr+".json", "a")
12+
#Store data in Json format
13+
output = {datatype : data}
14+
#Dump output to file
15+
json.dump(output, file, indent=2)
16+
file.close()
17+
print("\nData will be saved with a File Name :"+ "TorBoT-Export-"+datatype+timestr+".json")
18+
return
19+
20+
21+

tests/test_savetofile.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import sys
2+
import os
3+
import unittest
4+
from io import StringIO
5+
sys.path.append(os.path.abspath('../modules'))
6+
import getweblinks
7+
from bcolors import Bcolors
8+
import pagereader
9+
import time
10+
11+
soup = pagereader.readPage('http://www.whatsmyip.net/')
12+
timestr = time.strftime("%Y%m%d-%H%M%S")
13+
14+
class getLinksTestCase(unittest.TestCase):
15+
16+
def setUp(self):
17+
self.held, sys.stdout = sys.stdout, StringIO()
18+
self.maxDiff=None
19+
20+
def test_save_links(self):
21+
data = "\n"+Bcolors.OKGREEN+"Websites Found - "+Bcolors.ENDC+"1\n-------------------------------\nhttp://cmsgear.com/\n\nData will be saved with a File Name :"+ "TorBoT-Export-Onion-Links"+timestr+".json\n"
22+
ext = ['.com/']
23+
getweblinks.getLinks(soup,ext,0,1)
24+
self.assertEqual(sys.stdout.getvalue(),data)
25+
26+
27+
if __name__ == '__main__':
28+
unittest.main()
29+

torBot.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
from stem.control import Controller
1515

1616
with Controller.from_port(port = 9051) as controller:
17-
controller.authenticate("16:872860B76453A77D60CA2BB8C1A7042072093276A3D701AD684053EC4C")
17+
controller.authenticate("16:3BEA46EB6C489B90608A65120BD7CF0C7BA709513AB8ACF212B9537183")
1818
controller.signal(Signal.NEWNYM)
1919
#TorBot VERSION
2020
_VERSION_ = "1.0.1"
2121
#TOR SETUP GLOBAL Vars
22-
SOCKS_PORT = 9050 # TOR proxy port that is default from torrc, change to whatever torrc is configured to
22+
SOCKS_PORT = 9050 # TOR proxy port that is default from torrc, change to whatever torrc is configured to
2323
socks.set_default_proxy(socks.SOCKS5, "127.0.0.1",SOCKS_PORT)
2424
socket.socket = socks.socksocket
2525
# Perform DNS resolution through the socket
@@ -83,6 +83,7 @@ def main():
8383
parser.add_argument("--update",action="store_true",help="Update TorBot to the latest stable version")
8484
parser.add_argument("-q","--quiet",action="store_true")
8585
parser.add_argument("-u","--url",help="Specifiy a website link to crawl")
86+
parser.add_argument("-s","--save",action="store_true", help="Save results in a file")
8687
parser.add_argument("-m","--mail",action="store_true", help="Get e-mail addresses from the crawled sites")
8788
parser.add_argument("-e","--extension",action='append',dest='extension',default=[],help="Specifiy additional website extensions to the list(.com or .org etc)")
8889
parser.add_argument("-l","--live",action="store_true",help="Check if websites are live or not (slow)")
@@ -100,16 +101,18 @@ def main():
100101
link = args.url
101102
ext = 0
102103
live = 0
104+
save=0
103105
live = args.live
104106
ext = args.extension
107+
save = args.save
105108
a = readPage("https://check.torproject.org/",1)
106109
if link:
107110
b = readPage(link)
108111
else:
109112
b = readPage("http://torlinkbgs6aabns.onion/")
110113
if args.mail:
111-
getMails(b)
112-
getLinks(b,ext,live)
114+
getMails(b,save)
115+
getLinks(b,ext,live,save)
113116
print ("\n\n")
114117
return 0
115118

0 commit comments

Comments
 (0)