Last active
May 17, 2021 04:11
-
-
Save milo2012/de37531a26d6c6ffcf3a9da6655af5c3 to your computer and use it in GitHub Desktop.
Search Kali Repo (http.kali.org)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import requests | |
import optparse | |
from bs4 import BeautifulSoup | |
import multiprocessing | |
from requests.packages.urllib3.exceptions import InsecureRequestWarning | |
requests.packages.urllib3.disable_warnings(InsecureRequestWarning) | |
requests.packages.urllib3.disable_warnings() | |
def getHTML(url): | |
tmpTitle='' | |
try: | |
headers={'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:22.0) Gecko/20100101 Firefox/22.0'} | |
r = requests.get(url, headers=headers, verify=False, timeout=15,allow_redirects=True) | |
tmpData=r.text.encode('ascii','replace') | |
return tmpData | |
except Exception as e: | |
return | |
def getLinks(url): | |
resList=[] | |
#topUrl='http://http.kali.org/pool/main/' | |
tmpData=getHTML(url) | |
soup = BeautifulSoup(str(tmpData),'html.parser') | |
input = soup.find_all('a',{'href': True}) | |
for x in input: | |
if (x.text).endswith("/"): | |
resList.append(url+x.text) | |
return(resList) | |
def getPkgs(url): | |
url1=url | |
url1=url1[0:len(url1)-1] | |
resList=[] | |
topUrl='http://http.kali.org/pool/main/' | |
tmpData=getHTML(url) | |
soup = BeautifulSoup(str(tmpData),'html.parser') | |
input = soup.find_all('a',{'href': True}) | |
for x in input: | |
if "." in x.text: | |
#if (x.text).endswith("/"): | |
resList.append(url1+"/"+x.text) | |
return(resList) | |
parser = optparse.OptionParser() | |
parser.add_option('-f', action="store", dest="pkgName", help="partial text matching the package name") | |
options, remainder = parser.parse_args() | |
if options.pkgName: | |
url="http://http.kali.org/pool/main/" | |
resList=getLinks(url) | |
numOfThreads=4 | |
p = multiprocessing.Pool(processes=numOfThreads) | |
resList1 = p.map(getLinks,resList) | |
p.close() | |
for x in resList1: | |
for y in x: | |
resList2=getPkgs(y) | |
for z in resList2: | |
if options.pkgName in z: | |
print(z) | |
else: | |
print("[-] Please provide the -f option") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment