0w0

[primalsecurity] 0x6 – Spidering 본문

Primalsecurity/Primalsecurity_Python-tutorials

[primalsecurity] 0x6 – Spidering

0w0 2019. 12. 24. 15:14
728x90
반응형

Spidering ( 스파이더링 : 링크 파싱 및 검색 )

 

웹 어플리케이션에 대한 분석을 위해 링크된 경로와 URL구조를 파악

해당 모듈 (optparse, spider)을 사용

spider는 scrapy 모듈에 포함되어 v3에서는 "from scrapy.spiders import Spider" 로 모듈 호출

href 태그 파싱으로도 가능하지만 spider 모듈로 코드 간소화 가능

 

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
#!/usr/bin/python
#from spider import webspider as myspider
from scrapy.spiders import Spider as myspider
import sys, optparse
 
 
def crawler(URLs):
    for line in open(URLs, 'r'):
        URL = line.strip()
       ==================================
       ==================================
        out = URL + ": has a link count of " + str(link_count)
        print("[+] Web Crawl Results for: " + URL)
        print(out)
        for item in links[1]:
            print(item)
 
 
def main():
    # This optparse module allows you to build command line switches in your scripts
    # This will set the usage to '-r' and have it stored to a variable URLs
    # Then we will open the file given at the command line with -r and attempt to spider
    parser = optparse.OptionParser(sys.argv[0+ ' ' +'-r <file_with URLs>')
    parser.add_option('-r', dest='URLs', type='string', help='specify target file with URLs')
    (options, args) = parser.parse_args()
    URLs = options.URLs
    
    if (URLs == None):
        print(parser.usage)
        sys.exit(0)
    else:
        crawler(URLs)
 
 
if __name__ == "__main__":
    main()

 

10행과 11행 부분은 spider 구문 확인 후 크롤링 할 리소스, 스레드, 딥 범위 설정

 

타겟 설정 중 해당 코드 실행

 

#vim target

3210w0.tistory.com

 

#python script_test.py -r target

728x90
반응형
Comments