6
6
import argparse
7
7
import os
8
8
import re
9
+ import requests
9
10
import sys
10
11
import time
11
12
import warnings
12
13
13
- import requests
14
-
15
14
from core .colors import good , info , run , green , red , white , end
15
+
16
+ # Just a fancy ass banner
17
+ print ('''%s ____ __ __
18
+ / %s__%s \/ /_ ____ / /_____ ____
19
+ / %s/_/%s / __ \/ %s__%s \/ __/ %s__%s \/ __ \\
20
+ / ____/ / / / %s/_/%s / /_/ %s/_/%s / / / /
21
+ /_/ /_/ /_/\____/\__/\____/_/ /_/ %sv1.2.2%s\n ''' %
22
+ (red , white , red , white , red , white , red , white , red , white , red , white ,
23
+ red , white , end ))
24
+
25
+ try :
26
+ from urllib .parse import urlparse # For Python 3
27
+ except ImportError :
28
+ print ('%s Photon runs only on Python 3.2 and above.' % info )
29
+ quit ()
30
+
16
31
import core .config
17
32
from core .config import INTELS
18
33
from core .flash import flash
23
38
from core .utils import top_level , extract_headers , verb , is_link , entropy , regxy , remove_regex , timer , writer
24
39
from core .zap import zap
25
40
26
- try :
27
- from urllib .parse import urlparse # For Python 3
28
- python2 , python3 = False , True
29
- except ImportError :
30
- from urlparse import urlparse # For Python 2
31
- python2 , python3 = True , False
32
-
33
-
34
- try :
35
- input = raw_input
36
- except NameError :
37
- pass
38
-
39
-
40
- # Just a fancy ass banner
41
- print ('''%s ____ __ __
42
- / %s__%s \/ /_ ____ / /_____ ____
43
- / %s/_/%s / __ \/ %s__%s \/ __/ %s__%s \/ __ \\
44
- / ____/ / / / %s/_/%s / /_/ %s/_/%s / / / /
45
- /_/ /_/ /_/\____/\__/\____/_/ /_/ %sv1.2.1%s\n ''' %
46
- (red , white , red , white , red , white , red , white , red , white , red , white ,
47
- red , white , end ))
48
41
49
42
# Disable SSL related warnings
50
43
warnings .filterwarnings ('ignore' )
82
75
action = 'store_true' )
83
76
parser .add_argument ('--dns' , help = 'enumerate subdomains and DNS data' ,
84
77
dest = 'dns' , action = 'store_true' )
85
- parser .add_argument ('--ninja' , help = 'ninja mode' , dest = 'ninja' ,
86
- action = 'store_true' )
87
78
parser .add_argument ('--keys' , help = 'find secret keys' , dest = 'api' ,
88
79
action = 'store_true' )
89
80
parser .add_argument ('--update' , help = 'update photon' , dest = 'update' ,
118
109
timeout = args .timeout or 6 # HTTP request timeout
119
110
cook = args .cook or None # Cookie
120
111
api = bool (args .api ) # Extract high entropy strings i.e. API keys and stuff
121
- ninja = bool (args .ninja ) # Ninja mode toggle
122
112
crawl_level = args .level or 2 # Crawling level
123
113
thread_count = args .threads or 2 # Number of threads
124
114
only_urls = bool (args .only_urls ) # Only URLs mode is off by default
135
125
# URLs that have get params in them e.g. example.com/page.php?id=2
136
126
fuzzable = set ()
137
127
endpoints = set () # URLs found from javascript files
138
- processed = set () # URLs that have been crawled
128
+ processed = set ([ 'dummy' ] ) # URLs that have been crawled
139
129
# URLs that belong to the target i.e. in-scope
140
130
internal = set (args .seeds )
141
131
142
132
everything = []
143
- bad_intel = set () # Unclean intel urls
144
133
bad_scripts = set () # Unclean javascript file urls
145
134
146
135
core .config .verbose = verbose
180
169
181
170
supress_regex = False
182
171
183
- def intel_extractor (response ):
172
+ def intel_extractor (url , response ):
184
173
"""Extract intel from the response body."""
185
174
matches = re .findall (r'([\w\.-]+s[\w\.-]+\.amazonaws\.com)|([\w\.-]+@[\w\.-]+\.[\.\w]+)' , response )
186
175
if matches :
187
176
for match in matches :
188
177
verb ('Intel' , match )
189
- bad_intel .add (match )
178
+ intel .add (url + ':' + '' . join ( list ( match )) )
190
179
191
180
192
181
def js_extractor (response ):
@@ -198,12 +187,22 @@ def js_extractor(response):
198
187
verb ('JS file' , match )
199
188
bad_scripts .add (match )
200
189
190
+ def remove_file (url ):
191
+ if url .count ('/' ) > 2 :
192
+ replacable = re .search (r'/[^/]*?$' , url ).group ()
193
+ if replacable != '/' :
194
+ return url .replace (replacable , '' )
195
+ else :
196
+ return url
197
+ else :
198
+ return url
199
+
201
200
def extractor (url ):
202
201
"""Extract details from the response body."""
203
- response = requester (url , main_url , delay , cook , headers , timeout , host , ninja , user_agents , failed , processed )
202
+ response = requester (url , main_url , delay , cook , headers , timeout , host , user_agents , failed , processed )
204
203
if clone :
205
204
mirror (url , response )
206
- matches = re .findall (r'<[aA].* (href|HREF)=([^\s>]+)' , response )
205
+ matches = re .findall (r'<[aA][^>]*? (href|HREF)=([^\s>]+)' , response )
207
206
for link in matches :
208
207
# Remove everything after a "#" to deal with in-page anchors
209
208
link = link [1 ].replace ('\' ' , '' ).replace ('"' , '' ).split ('#' )[0 ]
@@ -219,19 +218,25 @@ def extractor(url):
219
218
elif link [:2 ] == '//' :
220
219
if link .split ('/' )[2 ].startswith (host ):
221
220
verb ('Internal page' , link )
222
- internal .add (schema + link )
221
+ internal .add (schema + '://' + link )
223
222
else :
224
223
verb ('External page' , link )
225
224
external .add (link )
226
225
elif link [:1 ] == '/' :
227
226
verb ('Internal page' , link )
228
- internal .add (main_url + link )
227
+ internal .add (remove_file ( url ) + link )
229
228
else :
230
229
verb ('Internal page' , link )
231
- internal .add (main_url + '/' + link )
230
+ usable_url = remove_file (url )
231
+ if usable_url .endswith ('/' ):
232
+ internal .add (usable_url + link )
233
+ elif link .startswith ('/' ):
234
+ internal .add (usable_url + link )
235
+ else :
236
+ internal .add (usable_url + '/' + link )
232
237
233
238
if not only_urls :
234
- intel_extractor (response )
239
+ intel_extractor (url , response )
235
240
js_extractor (response )
236
241
if args .regex and not supress_regex :
237
242
regxy (args .regex , response , supress_regex , custom )
@@ -245,7 +250,7 @@ def extractor(url):
245
250
246
251
def jscanner (url ):
247
252
"""Extract endpoints from JavaScript code."""
248
- response = requester (url , main_url , delay , cook , headers , timeout , host , ninja , user_agents , failed , processed )
253
+ response = requester (url , main_url , delay , cook , headers , timeout , host , user_agents , failed , processed )
249
254
# Extract URLs/endpoints
250
255
matches = re .findall (r'[\'"](/.*?)[\'"]|[\'"](http.*?)[\'"]' , response )
251
256
# Iterate over the matches, match is a tuple
@@ -301,10 +306,8 @@ def jscanner(url):
301
306
if '=' in url :
302
307
fuzzable .add (url )
303
308
304
- for match in bad_intel :
305
- for x in match : # Because "match" is a tuple
306
- if x != '' : # If the value isn't empty
307
- intel .add (x )
309
+ for match in intel :
310
+ intel .add (match )
308
311
for url in external :
309
312
try :
310
313
if top_level (url , fix_protocol = True ) in INTELS :
0 commit comments