import requests
import re
import subprocess
import os
import json
from multiprocessing.dummy import Pool
import threading
import socket
from bs4 import BeautifulSoup
import time
import random
import sys
from colorama import Fore,Back,init
import sys
from requests.packages.urllib3.exceptions import InsecureRequestWarning
from colorama import Fore,Back,init
import datetime



requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
init()


class Yuyu():
	def __init__(self, args):

		# API KEY
		self.hunter_io = "b669c6dbe6b16ef7cda65fa1671fdc1cf7f14705"
		self.virus_total = "427ca61f3859dc9534ae90bc7afe9c45aff5b0a5b1858af3e794ace55c5514eb"
		
		# Color
		self.red  = '\033[91m'
		self.blue  = '\033[94m'
		self.green = '\033[92m'
		self.white = '\033[00m'
		self.cyan    = '\033[0;96m'


		# Data
		self.date = datetime.datetime.now().date()
		self.target = args.url
		self.subdomain =	 []
		self.live_subdomain = []
		self.ip = []
		self.revip = []
		self.links = []
		self.email = []
		self.file = []
		self.port = []
		self.whoisl = []


		self.starter(args)

		

	def starter(self, args):
		self.banner()
		if args.gui == True:
			os.system("bash gui.sh run")
		else:
			if args.url:

				# scan subdomain

				self.scansubdo(args.url)


				# show result subdomain

				print(self.white+"\n\n["+self.green+"+"+self.white+"] Subdomain\n----------------------------------")
				for i in self.subdomain:
					print(self.white+"\t["+self.blue+">"+self.white+"] "+i.strip())
					self.save("subdomain.txt", i.strip()+"\n")

				# Check a Response status and IP Discovery

				print(self.white+"\n\n["+self.green+"+"+self.white+"] Checking Response Status Code\n----------------------------------")

				x = Pool(int(len(self.subdomain)))
				x.map(self.checkdomain, self.subdomain)

				# show result status
				
				for data in self.live_subdomain:
					print(self.white+"\t["+self.blue+">"+self.white+"] "+data[0].strip()+ " " + self.white+"["+self.green+data[2].strip()+self.white+"] ")
					self.save("subdomain_status.txt", data[0].strip()+" | "+data[2].strip()+"\n")




				# show IP Discovery
				
				print(self.white+"\n\n["+self.green+"+"+self.white+"] IP Discovery\n----------------------------------")
				time.sleep(1)
				for data in self.live_subdomain:
					print(self.white+"\t["+self.blue+">"+self.white+"] "+data[0].strip()+ " " + self.white+"["+self.green+data[1].strip()+self.white+"] ")
					self.save("ip_discovery.txt", data[0].strip()+" | "+data[1].strip()+"\n")
					if data[1].strip() not in self.ip:
						self.ip.append(data[1].strip())


				# show title discovery

				print(self.white+"\n\n["+self.green+"+"+self.white+"] Checking Web Title\n----------------------------------")
				time.sleep(1)
				for data in self.live_subdomain:
					print(self.white+"\t["+self.blue+">"+self.white+"] "+data[0].strip()+ " " + self.white+"["+self.green+data[3].strip()+self.white+"] ")
					self.save("title.txt", data[0].strip()+" | "+data[3].strip()+"\n")




				# check true arguments

				# Scan Port
				
				if args.scanport == True:
					print(self.white+"\n\n["+self.green+"+"+self.white+"] Scanning Top 10 Port\n----------------------------------")
					ip = []
					for i in self.live_subdomain:
						if i not in ip:
							ip.append(i[1])

					# start nmap
					
					x = Pool(len(ip))
					x.map(self.scan_port, ip)

					# show result nmap
					
					for a in self.port:
						print(self.white+"["+self.blue+"!"+self.white+"] "+a["url"].strip()+ "\n" + self.white+""+self.green+a["result"].strip()+self.white+"")
						self.save("port_scan.txt", a["url"].strip()+"\n"+a["result"].strip()+"\n\n")

				# delay
				time.sleep(1)

				
				
				# Reverse IP
				
				if args.revip == True:
					print(self.white+"\n\n["+self.green+"+"+self.white+"] Starting Reverse IP\n----------------------------------")

					# start reverse ip

					self.reverseip(self.target)

					# show result nmap

					if len(self.revip) != 0:
						if "API" in self.revip and "count" in self.revip and  "exceeded" in self.revip:
							print(self.white+"["+self.red+"!"+self.white+"] "+"Limited Requests From HackerTarget")
							self.save("reverseip.txt", "Limited IP\n")

						else:
							for a in self.revip:
								print(self.white+"\t["+self.blue+">"+self.white+"] "+a.strip())
								self.save("reverseip.txt", a.strip()+"\n")


					else:
						print(self.white+"["+self.red+"!"+self.white+"] "+"Not Found Result")
						self.save("reverseip.txt", " No result\n")

				# delay
				time.sleep(1)



				# Whois Lookup
				
				if args.whois == True:
					print(self.white+"\n\n["+self.green+"+"+self.white+"] Starting Whois\n----------------------------------")
					
					# Start whois lookup
					
					x = Pool(len(self.subdomain))
					x.map(self.whois, self.subdomain)

					# show result whois
					
					for i in self.whoisl:
						print(self.white+"\t["+self.blue+">"+self.white+"] "+i['url'].strip()+ " " + self.white+"["+self.green+"OK"+self.white+"] ")
						self.save("whois.txt", "-----------------------------------------------------------------------------------\n"+i['url']+"\n"+i['result']+"\n\n")


				# delay
				time.sleep(1)

					

				# Collect URL

				if args.collecturl == True:
					print(self.white+"\n\n["+self.green+"+"+self.white+"] Starting Collect Url from Waybackurl\n----------------------------------")
					
					# Start Collecting

					self.collect_url(self.target)

					# show result whois

					print(self.white+"\t["+self.blue+">"+self.white+"] Found "+str(len(self.links))+ " URL!")

					if len(self.file) != 0:
						for i in self.links:
							self.save("colleted_url.txt", i+"\n")

					else:
						self.save("colleted_url.txt", "colleted url Not Found\n")




				# delay
				time.sleep(1)



				# Email Discovery
				
				if args.emaildiscover == True:
					print(self.white+"\n\n["+self.green+"+"+self.white+"] Starting Collect Email Address\n----------------------------------")

					# starting email discovery

					self.emaildiscovery(self.target)
					
					# show result whois

					if len(self.email) != 0:
						for i in self.email:
							print(self.white+"\t["+self.blue+">"+self.white+"] "+i.strip())
							self.save("email.txt", i.strip()+"\n")
					else:
							print(self.white+"\t["+self.red+"!"+self.white+"] "+"Email Not Found")
							self.save("email.txt", "Email Not Found\n")


				# delay
				time.sleep(1)


				if args.filesensitive == True:
					print(self.white+"\n\n["+self.green+"+"+self.white+"] Checking Sensitive File\n----------------------------------")
					liss = [i.strip() for i in open("seed/file.txt", "r").readlines()]
					
					# starting email discovery

					aw = Pool(int(len(liss)))
					aw.map(self.sensitive, liss)

					if len(self.file) != 0:
						for data in self.file:
							print(self.white+"\t["+self.blue+">"+self.white+"] "+data.strip()+ " " + self.white+"["+self.green+"Found"+self.white+"] ")
							self.save("sensitive_file.txt", data.strip()+"\n")

					else:
						print(self.white+"\t["+self.red+"!"+self.white+"] "+"No Sensitive File Found")
						self.save("sensitive_file.txt", "Sensitive File Not Found\n")

				time.sleep(5)

				
				# generate json file
				self.all_data = {
					"target": self.target,
					"date": self.date,
					"subdomain": self.subdomain,
					"live_subdomain": self.live_subdomain,
					"ip": self.ip,
					"revip": self.revip,
					"links": self.links,
					"email": self.email,
					"file": self.file,
					"file": self.file,
					"port": self.port,
					"port": self.port,
					"whois": self.whoisl
				}
				self.save("result.json", self.all_data)
				try:
					# Generate json.
					
					# generate report

					self.html()
				except:
					pass
				print(self.white+"\n\n["+self.green+"+"+self.white+"] Result saved to:\n----------------------------------")
				print(self.white+"\t["+self.blue+">"+self.white+"] output/"+str(self.date)+"/"+self.target  )

				# print Output
				# print("Result saved to :\n\toutput/"+str(self.date)+"/"+self.target )

	def html(self):
		data = self.all_data
		# data = json.loads(r)

		target = data['target']

		subdomain = ""
		status_code = ""
		ipaddress = ""
		title = ""
		port = ""
		revip = ""
		whois = ""
		email = ""
		file = ""



		# subdomain
		num = 1
		for i in data['subdomain']:
			td = "<tr><td>{number}</td><td>{domain}</td></tr>".format(number = str(num), domain = i)
			subdomain += td

			num+=1

		# status code
		num = 1
		for i in data['live_subdomain']:
			td = "<tr><td>{number}</td><td>{domain}</td><td>{status}</td></tr>".format(number = str(num), domain = i[0], status=i[2])
			status_code += td
			num+=1

		# IP Address
		num = 1
		for i in data['live_subdomain']:
			td = "<tr><td>{number}</td><td>{domain}</td><td>{ip}</td></tr>".format(number = str(num), domain = i[0], ip=i[1])
			ipaddress += td
			num+=1

		# Titile
		num = 1
		for i in data['live_subdomain']:
			td = "<tr><td>{number}</td><td>{domain}</td><td>{title}</td></tr>".format(number = str(num), domain = i[0], title=i[3])
			title += td
			num+=1

		# port
		num = 1
		for i in data['port']:
			td = "<tr><td>{number}</td><td>{ip}</td><td><pre>{result}</pre></td></tr>".format(number = str(num), ip = i["url"], result=i['result'])
			port += td
			num+=1

		num = 1
		for i in data['revip']:
			td = "<tr><td>{number}</td><td>{domain}</td></tr>".format(number = str(num), domain = i)
			revip += td
			num+=1


		num = 1
		for i in data['whois']:
			td = "<tr><td>{number}</td><td>{domain}</td><td><pre>{result}</pre></td></tr>".format(number = str(num), domain = i['url'], result=i['result'])
			whois += td
			num+=1


		num = 1
		for i in data['email']:
			td = "<tr><td>{number}</td><td>{email}</td></tr>".format(number = str(num), email = i)
			email += td
			num+=1

		num = 1
		for i in data['file']:
			td = "<tr><td>{number}</td><td>{file}</td></tr>".format(number = str(num), file = i)
			file += td
			num+=1



		html = """


		<!doctype html>
		<html lang="en">
		  <head>
		    <!-- Required meta tags -->

		    <!-- Bootstrap CSS -->
		    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
		    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.2/css/bootstrap.css">
		    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.25/css/dataTables.bootstrap4.min.css">
		  
		    <title>Yuyu Scanner - Web Information Gathering Report</title>
		  </head>
		  <body>
		    <nav class="navbar navbar-expand-lg navbar navbar-dark bg-dark mb-1">
		      <div class="container-fluid">
		        <a class="navbar-brand" href="#">Yuyu Scanner</a>
		        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
		          <span class="navbar-toggler-icon"></span>
		        </button>
		        <div class="collapse navbar-collapse" id="navbarNavAltMarkup">
		          <div class="navbar-nav">
		            <a class="nav-link active" aria-current="page" href="#about" data-bs-toggle="modal" data-bs-target="#exampleModal">About</a>
		          </div>
		        </div>
		      </div>
		    </nav>
		    <div class="container-fluid">
		        <div class="row mb-3">
		            <div class="col-md-12">
		                <img src="https://raw.githubusercontent.com/justakazh/Yuyu-Scanner/main/y.png" class="img-fluid position-relative top-50 start-50 translate-middle  " alt="...">
		            </div>
		        </div>
		        <div class="row">
		            <div class="col-md-2">
		                <div class="card  bg-primary text-white">
		                  <div class="card-body">
		                    <a href="#domain" class="text-white" style="text-decoration: none;"><b>"""+str(len(data['subdomain']))+""" Subdomain <br>Found!</b></a>
		                  </div>
		                </div>  
		            </div>
		            <div class="col-md-2">
		                <div class="card  bg-danger text-white">
		                  <div class="card-body">
		                    <a href="#domain" class="text-white" style="text-decoration: none;"><b>"""+str(len(data['live_subdomain']))+""" IP Address <br>Found!</b></a>
		                  </div>
		                </div>  
		            </div>
		            <div class="col-md-2">
		                <div class="card  bg-primary text-white">
		                  <div class="card-body">
		                    <a href="#domain" class="text-white" style="text-decoration: none;"><b>"""+str(len(data['revip']))+""" Reverse <br>Found!</b></a>
		                  </div>
		                </div>  
		            </div>
		            <div class="col-md-2">
		                <div class="card  bg-danger text-white">
		                  <div class="card-body">
		                    <a href="#domain" class="text-white" style="text-decoration: none;"><b>"""+str(len(data['links']))+""" Links <br>Found!</b></a>
		                  </div>
		                </div>  
		            </div>
		            <div class="col-md-2">
		                <div class="card  bg-primary text-white">
		                  <div class="card-body">
		                    <a href="#domain" class="text-white" style="text-decoration: none;"><b>"""+str(len(data['port']))+""" Ports <br>Scanned!</b></a>
		                  </div>
		                </div>  
		            </div>
		            <div class="col-md-2">
		                <div class="card  bg-danger text-white">
		                  <div class="card-body">
		                    <a href="#domain" class="text-white" style="text-decoration: none;"><b>"""+str(len(data['file']))+""" Sensitive File <br>Found!</b></a>
		                  </div>
		                </div>  
		            </div>
		        </div>
		        <div class="container">
		            <div class="row mt-5">
		                <div class="col-md-6">
		                    <div class="card shadow-sm p-3 mb-5 bg-white rounded">
		                        <div class="card-body">
		                            <h3>Subdomain</h3>
		                            <table  id="example" class="table table-striped table-bordered" style="width:100%">
		                                <thead>
		                                    <tr>
		                                        <th>#</th>
		                                        <th>Subdomain</th>
		                                    </tr>
		                                </thead>
		                                <tbody>
		                                  """+subdomain+"""
		                                </tbody>
		                                <tfoot>
		                                    <tr>
		                                        <th>#</th>
		                                        <th>Subdomain</th>
		                                    </tr>
		                                </tfoot>
		                            </table>
		                        </div>
		                    </div>  
		                </div>
		                <div class="col-md-6">
		                    <div class="card shadow-sm p-3 mb-5 bg-white rounded">
		                        <div class="card-body">
		                            <h3>Status Code</h3>
		                            <table  id="example" class="table table-striped table-bordered" style="width:100%">
		                                <thead>
		                                    <tr>
		                                        <th>#</th>
		                                        <th>Domain</th>
		                                        <th>Status Code</th>
		                                    </tr>
		                                </thead>
		                                <tbody>
		                                  """+status_code+"""
		                                </tbody>
		                                <tfoot>
		                                    <tr>
		                                        <th>#</th>
		                                        <th>Domain</th>
		                                        <th>Status Code</th>
		                                    </tr>
		                                </tfoot>
		                            </table>
		                        </div>
		                    </div>  
		                </div>
		                <div class="col-md-6">
		                    <div class="card shadow-sm p-3 mb-5 bg-white rounded">
		                        <div class="card-body">
		                            <h3>IP Address</h3>
		                            <table  id="example" class="table table-striped table-bordered" style="width:100%">
		                                <thead>
		                                    <tr>
		                                        <th>#</th>
		                                        <th>Domain</th>
		                                        <th>IP</th>
		                                    </tr>
		                                </thead>
		                                <tbody>
		                                """+ipaddress+"""
		                                </tbody>
		                                <tfoot>
		                                    <tr>
		                                        <th>#</th>
		                                        <th>Domain</th>
		                                        <th>IP</th>
		                                    </tr>
		                                </tfoot>
		                            </table>
		                        </div>
		                    </div>  
		                </div>
		                <div class="col-md-6">
		                    <div class="card shadow-sm p-3 mb-5 bg-white rounded">
		                        <div class="card-body">
		                            <h3>Email</h3>
		                            <table  id="scan" class="table table-striped table-bordered" style="width:100%">
		                                <thead>
		                                    <tr>
		                                        <th>#</th>
		                                        <th>Email</th>
		                                    </tr>
		                                </thead>
		                                <tbody>
		                                  """+email+"""
		                                </tbody>
		                                <tfoot>
		                                    <tr>
		                                        <th>#</th>
		                                        <th>Email</th>
		                                    </tr>
		                                </tfoot>
		                            </table>
		                        </div>
		                    </div>  
		                </div>
		                <div class="col-md-6">
		                    <div class="card shadow-sm p-3 mb-5 bg-white rounded">
		                        <div class="card-body">
		                            <h3>Sensitive File</h3>
		                            <table  id="scan" class="table table-striped table-bordered" style="width:100%">
		                                <thead>
		                                    <tr>
		                                        <th>#</th>
		                                        <th>File</th>
		                                    </tr>
		                                </thead>
		                                <tbody>
		                                  """+file+"""
		                                </tbody>
		                                <tfoot>
		                                    <tr>
		                                        <th>#</th>
		                                        <th>File</th>
		                                    </tr>
		                                </tfoot>
		                            </table>
		                        </div>
		                    </div>  
		                </div>
		                <div class="col-md-6">
		                    <div class="card shadow-sm p-3 mb-5 bg-white rounded">
		                        <div class="card-body">
		                            <h3>Reverse IP</h3>
		                            <table  id="example" class="table table-striped table-bordered" style="width:100%">
		                                <thead>
		                                    <tr>
		                                        <th>#</th>
		                                        <th>Domain</th>
		                                    </tr>
		                                </thead>
		                                <tbody>
		                                    """+revip+"""                                  
		                                </tbody>
		                                <tfoot>
		                                    <tr>
		                                        <th>#</th>
		                                        <th>Domain</th>
		                                    </tr>
		                                </tfoot>
		                            </table>
		                        </div>
		                    </div>  
		                </div>
		                <div class="col-md-12">
		                    <div class="card shadow-sm p-3 mb-5 bg-white rounded">
		                        <div class="card-body">
		                            <h3>Title</h3>
		                            <table  id="example" class="table table-striped table-bordered" style="width:100%">
		                                <thead>
		                                    <tr>
		                                        <th>#</th>
		                                        <th>Domain</th>
		                                        <th>Title</th>
		                                    </tr>
		                                </thead>
		                                <tbody>
		                                    """+title+"""
		                                </tbody>
		                                <tfoot>
		                                    <tr>
		                                        <th>#</th>
		                                        <th>Domain</th>
		                                        <th>Title</th>
		                                    </tr>
		                                </tfoot>
		                            </table>
		                        </div>
		                    </div>  
		                </div>
		                <div class="col-md-12">
		                    <div class="card shadow-sm p-3 mb-5 bg-white rounded">
		                        <div class="card-body">
		                            <h3>Links</h3>
		                            <table  id="example" class="table table-striped table-bordered" style="width:100%">
		                                <thead>
		                                    <tr>
		                                        <th>#</th>
		                                        <th>Domain</th>
		                                    </tr>
		                                </thead>
		                                <tbody>
		                                    <tr>
		                                    	<td>!</td>
		                                    	<td>Sorry, Please open file in output folder.</td>
		                                    </tr>
		                                </tbody>
		                                <tfoot>
		                                    <tr>
		                                        <th>#</th>
		                                        <th>Domain</th>
		                                    </tr>
		                                </tfoot>
		                            </table>
		                        </div>
		                    </div>  
		                </div>
		                <div class="col-md-12">
		                    <div class="card shadow-sm p-3 mb-5 bg-white rounded">
		                        <div class="card-body">
		                            <h3>Ports Scanned</h3>
		                            <table  id="scan" class="table table-striped table-bordered" style="width:100%">
		                                <thead>
		                                    <tr>
		                                        <th>#</th>
		                                        <th>Domain</th>
		                                        <th>Result Scan</th>
		                                    </tr>
		                                </thead>
		                                <tbody>
		                                  """+port+"""
		                                </tbody>
		                                <tfoot>
		                                    <tr>
		                                        <th>#</th>
		                                        <th>Domain</th>
		                                        <th>Result Scan</th>
		                                    </tr>
		                                </tfoot>
		                            </table>
		                        </div>
		                    </div>  
		                </div>
		                <div class="col-md-12">
		                    <div class="card shadow-sm p-3 mb-5 bg-white rounded">
		                        <div class="card-body">
		                            <h3>Whois</h3>
		                            <table  id="scan" class="table table-striped table-bordered" style="width:100%">
		                                <thead>
		                                    <tr>
		                                        <th>#</th>
		                                        <th>Domain</th>
		                                        <th>Result Scan</th>
		                                    </tr>
		                                </thead>
		                                <tbody>
		                                  """+whois+"""
		                                </tbody>
		                                <tfoot>
		                                    <tr>
		                                        <th>#</th>
		                                        <th>Domain</th>
		                                        <th>Result Scan</th>
		                                    </tr>
		                                </tfoot>
		                            </table>
		                        </div>
		                    </div>  
		                </div>
		            </div>
		        </div>
		    </div>
		<!-- Modal -->
		<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
		  <div class="modal-dialog">
		    <div class="modal-content">
		      <div class="modal-header">
		        <h5 class="modal-title" id="exampleModalLabel">About Yuyu Scanner</h5>
		        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
		      </div>
		      <div class="modal-body">
		        <strong>Yuyu Scanner is a Web Information Gathering Tool</strong>
		        <p></p>
		      </div>
		      <div class="modal-footer">
		        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
		      </div>
		    </div>
		  </div>
		</div>
		    <!-- Optional JavaScript; choose one of the two! -->

		    <!-- Option 1: Bootstrap Bundle with Popper -->
		    <script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
		    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>
		    <script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.23/js/jquery.dataTables.js"></script>
		    <script type="text/javascript" src="https://cdn.datatables.net/1.10.25/js/dataTables.bootstrap4.min.js"></script>
		    <script type="text/javascript">
		        $(document).ready(function() {
		            $('table').DataTable( {
		                "scrollX": true
		            } );
		        } );
		    </script>
		    <script type="text/javascript">
		        $(document).ready(function() {
		            $('scan').DataTable();
		        } );
		    </script>

		    <!-- Option 2: Separate Popper and Bootstrap JS -->
		    <!--
		    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.4/dist/umd/popper.min.js" integrity="sha384-q2kxQ16AaE6UbzuKqyBE9/u/KzioAlnx2maXQHiDX9d4/zp8Ok3f+M7DPm+Ib6IU" crossorigin="anonymous"></script>
		    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.min.js" integrity="sha384-pQQkAEnwaBkjpqZ8RU1fF1AKtTcHJwFl3pblpTlHXybJjHpMYo79HY3hIi4NKxyj" crossorigin="anonymous"></script>
		    -->
		  </body>
		</html>


		"""
		# print(html)
		self.save("report.html", html)




	def save(self,name, data):
		try:
			try:
				pwd = os.getcwd()
				self.Outputs = os.path.join(pwd, "output/"+str(self.date)+"/"+self.target)
				os.makedirs(self.Outputs)
			except:
				pass
			open(self.Outputs+"/"+name, "a").write(data)
		
		except:
			pass


	def banner(self):
		clear = "\x1b[0m"
		colors = [36, 32, 34, 35, 31, 37  ]
		x = """

                                                                                 
                                                                                
                                                                                
                                                                                
                                                                 ,              
             #/                                                   *%,           
           (%/  (,                                             *%  (%%          
          *%%( #%#                            .               .%%%(%%%*         
          (%%%%%%%%#             (%(         *%%            .#%%%%%%%%*         
          .%%%%%%%%%.             #*(%&%%%&&%*#.             #%%%%%%%%          
           .%%%%%%%%%%(.   .(&&%%%%%%%%%%%%%%%%%%%&&%,. ./%%%%%%%%%%,           
              *#%%%%%%%%#.%%%%%%%%%%%%%&%%&&%%&&&&&&&&&**%%%%%%%(.              
                 (%%%%%%/.%%%%%%%%%%%%%%&%%%%%%%%%%%%%%*.%%%%%%,                
                   *%%%%#.%%%%%%%%%%%%%%&%%%%%%%%%%%%%%*/%%#,                   
                          %%%%%%%%%%%%%%%%%%%%%%%%%%%%&.                        
                          /%%%%%%%%%%%%&%%&&&&&&&&&&&&&                         
                           #%%%%%%%%%%%%%%%%%%%%%%%%%&....                      
                .*%%%%#(//. (%%%%%%%%%%&%%&%%&%%%%%%%. //((%%%%(,               
               (%*        .* (%%%%%%%%%%&%%%%&%%%%%%..,        ,#%.             
                       #%%#.   %%%%%%%%%&%%&&%&%%&*  .(%%%,                     
                     .%%.    .%( *%%%%%%&%%%%%&% *%,     %%*                    
                     (%*     #%*    ./&&&&&(,    .%#.    .%%.                   
                             *%%                 (%(                            
                               .                 */                             
                                                                                
 
Yuyu is a Web Reconnaissance & Web Analysis Scanner by @justakazh
------------------------------------------------------------------------------------------------------------"""
		for N, line in enumerate(x.split("\n")):
			sys.stdout.write("\x1b[1;%dm%s%s\n" % (random.choice(colors), line, clear))
			time.sleep(0.05)
		print(self.red+"""
\t[!] It's the end user's responsibility to obey all applicable local, state and federal laws. 
\tDevelopers assume no liability and are not responsible for any misuse or damage caused by this program. 
\tOnly use for educational purposes.
		""")
		print(self.white+"\t["+self.red+"!"+self.white+"] usage: yuyu.py -h")
		print(self.white+"\t["+self.blue+"!"+self.white+"] Make sure your connection is good!")
		


	def scan_port(self,ip):
		try:
			if "*." not in ip:
				if ":" not in ip:
					cmd = subprocess.getoutput("nmap -F --top-ports 10 "+ip)
					self.port += [{'url':ip, 'result':cmd}]
		except:
			pass
		# print(self.port)

	def req_sensitive(self, url):
		try:
			r = requests.get(url, timeout=20)
			r2 = requests.post(url, data={"1[]":"1"}, timeout=20)
				
			
			if "APP_KEY" in r2.text or "DB_NAME" in r2.text:
				self.file.append(self.target+" | Stack Trace")
			
			#######################################
			# YOU CAN ADD A CUSTOM RESPONSE HERE  #
			#######################################

			if "APP_KEY" in r.text or "DB_NAME" in r.text:
				self.file.append(url)

			if "ref: refs/" in r.text: 
				self.file.append(url)

			if r.status_code == 200:
				if "PHP Version" in r.text or "Build Date" in r.text:
					self.file.append(url)

			if r.status_code == 200:
				if "Disallow" in r.text or "User-agent:" in r.text:
					self.file.append(url)
		except:
			pass


	def sensitive(self, path):
		urls = []
		for i in self.live_subdomain:
			url = "http://"+i[0]+path
			urls += [url]
		a = len(urls) / 2
		asd = Pool(int(a))
		asd.map(self.req_sensitive, urls)





	def emaildiscovery(self, url):
		try:
			r = requests.get("https://api.hunter.io/v2/domain-search?domain="+url+"&api_key="+self.hunter_io)
			de = json.loads(r.text)
			for email in de['data']["emails"]:
				if email['value'] not in self.email:
					self.email.append(email['value'])
		except:
			pass

	def whois(self, url):
		cmd = subprocess.getoutput("whois "+url)
		self.whoisl.append({"url":url, "result":cmd})
		


	
		
	def collect_url(self,url):
		try:
			r = requests.get("http://web.archive.org/cdx/search/cdx?url=*."+url+"/&output=text&fl=original&collapse=urlkey").text
			res = r.split()
			for i in res:
				if i not in self.links:
					self.links.append(i)

			r = requests.get("http://web.archive.org/cdx/search/cdx?url=*."+url+"/&output=text&fl=original&collapse=urlkey").text
			res = r.split()
			for i in res:
				if i not in self.links:
					self.links.append(i)
			
			r = requests.get("http://index.commoncrawl.org/CC-MAIN-2021-17-index?url=*."+url+"/*&output=json", timeout=10).text
			rex = re.findall('"url": "(.*?)"',r)
			for i in rex:
				if i not in self.links:
					self.links.append(i)
		except:
			pass




	def reverseip(self,url):
		r = requests.get("http://api.hackertarget.com/reverseiplookup/?q="+url).text
		domain = r.split()
		for site in domain:
			self.revip.append(site)


	def subdo(self,url):
		# You can grab your subdomain result from your best API here

		if "web.archive.org" in url:
			try:
				r = requests.get(url, timeout=3).text
				pecah = r.split("\n")
				for i in pecah:
					url = i.split("\r")
					for ii in url:
						try:
							domains = ii.split("/")
							if self.target not in domains[2]:
								pass
							else:
								if ":" in domains[2]:
									domain = domains[2].split(":")
									if domain[0] not in self.subdomain: 
										self.subdomain.append(domain[0])
								else:
									if domains[2] not in self.subdomain: 
										self.subdomain.append(domains[2])
						except:
							pass
			except:
				pass

		elif "threatcrowd.org" in url:
			try:
				r = requests.get(url, timeout=3).text
				de = json.loads(r)
				lis = de['subdomains']
				for domain in lis:
					try:
						if self.target not in domain:
							pass
						else:
							if domain not in self.subdomain:
								self.subdomain.append(domain)
					except:
						pass
			except:
				pass

		elif "urlscan.io" in url:
			try:
				r = requests.get(url, timeout=3).text
				de = json.loads(r)
				for i in de['results']:
					try:
						if self.target not in i['task']['domain']:
							pass
						else:
							if i['task']['domain'] not in self.subdomain:
								self.subdomain.append(i['task']['domain'])
					except:
						pass
			except:
				pass

		elif "rapiddns.io" in url:
			try:
				r = requests.get(url, timeout=3).text
				rex = re.findall('<td><a href="http(.*?)" target="_blank">(.*?)</a></td>', r)
				for i in rex:
					try:
						if self.target not in i[1]:
							pass
						else:
							if i[1] not in self.subdomain:
								self.subdomain.append(i[1])
					except:
						pass
			except:
				pass

		elif "otx.alienvault.com" in url:
			try:
				r = requests.get(url, timeout=3).text
				de = json.loads(r)
				for i in de['passive_dns']:
					try:
						if self.target not in i['hostname']:
							pass
						else:
							if i['hostname'] not in self.subdomain:
								self.subdomain.append(i['hostname'])

					except:
						pass
			except:
				pass

		elif "dnsdumpster.com" in url:
			try:
				r = requests.get("https://dnsdumpster.com/", timeout=3).text
				rex = re.findall('value="(.*?)"', r)
				csrf = rex[0]
				
				x = url.split("/")

				data = {
				"csrfmiddlewaretoken": csrf,
				"targetip": x[3]
				}

				rr = requests.post("https://dnsdumpster.com/", data=data, headers={
					"content-type": "application/x-www-form-urlencoded",
					"cookie": "csrftoken="+csrf+"; _ga=GA1.2.1216996729.1609624762; _gid=GA1.2.1247250058.1609624762; _gat=1",
					"origin": "https://dnsdumpster.com",
					"referer": "https://dnsdumpster.com/",
					"sec-ch-ua": '"Google Chrome";v="87", " Not;A Brand";v="99", "Chromium";v="87"',
					"sec-ch-ua-mobile": "?0",
					"sec-fetch-dest": "document",
					"sec-fetch-mode": "navigate",
					"sec-fetch-site": "same-origin",
					"sec-fetch-user": "?1",
					"upgrade-insecure-requests": "1",
					"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"

					}).text
				rex = re.findall('<a class="external nounderline" data-toggle="modal" href="(.*?)" data-target="#myModal">', rr)
				for a in rex:
					if "httpheaders" in a:
						url = a.replace("https://api.hackertarget.com/httpheaders/?q=", "")
						domain = url.replace("http://","").replace("https://","").replace("/", "")
						if self.target not in domain:
							pass
						else:
							if domain not in self.subdomain:
								self.subdomain.append(domain)
			except:
				pass


		elif "crt.sh" in url:
			try:
				r = requests.get(url, timeout=3).text
				de = json.loads(r)
				for i in de:
					try:
						if "*." not in i['common_name']:
							if self.target not in i['common_name']:
								pass
							else:
								if i['common_name'] not in self.subdomain:
									self.subdomain.append(i['common_name'])
					except:
						pass
			except:
				pass

		elif "api.threatminer.org" in url:
			try:
				r = requests.get(url, timeout=3).text
				de = json.loads(r)
				for i in de['results']:
					try:
						if self.target not in i:
							pass
						else:
							if i not in self.subdomain:
								self.subdomain.append(i)
					except:
						pass
			except:
				pass

		elif "api.certspotter.com" in url:
			try:
				r = requests.get(url, timeout=3).text
				de = json.loads(r)
				for i in de:
					try:
						if self.target not in i['dns_names'][0]:
							pass
						else:
							if "*" not in i['dns_names'][0]:
								if i['dns_names'][0] not in self.subdomain:
									self.subdomain.append(i['dns_names'][0])
					except:
						pass
			except:
				pass

		elif "api.hackertarget.com" in url:
			try:
				r = requests.get(url, timeout=3).text
				pecah = r.split("\n")
				for i in pecah:
					try:
						domain = i.split(",")
						if self.target not in domain[0]:
							pass
						else:
							if domain[0] not in self.subdomain:
								self.subdomain.append(domain[0])
					except:
						pass
			except:
				pass

		elif "riddler.io" in url:
			try:
				r = requests.get(url, timeout=3).text
				rex = re.findall(",(.*?),", r)
				for i in rex:
					try:
						if self.target not in i:
							pass
						else:
							if i in self.url:
								if i not in self.subdomain:
									self.subdomain.append(i)
					except:
						pass
			except:
				pass

		elif "index.commoncrawl.org" in url:
			try:
				r = requests.get(url, timeout=3).text
				rex = re.findall(', "url": "(.*?)",',r)
				for i in rex:
					try:
						url = i.split("/")
						domain = url[2].lower()
						if self.target not in domain:
							pass
						else:
							if domain not in self.subdomain:
								self.subdomain.append(domain)
					except:
						pass
			except:
				pass

		else:
			pass

	def scansubdo(self, url):
		# You can add Your best API Here 
		api = [
			"http://web.archive.org/cdx/search/cdx?url=*."+url+"/&output=text&fl=original&collapse=urlkey",
			"https://threatcrowd.org/searchApi/v2/domain/report/?domain="+url,
			"https://urlscan.io/api/v1/search/?q="+url,
			"https://rapiddns.io/subdomain/"+url,
			"https://otx.alienvault.com/api/v1/indicators/domain/"+url+"/passive_dns",
			"https://dnsdumpster.com/"+url,
			"https://crt.sh/?q="+url+"&output=json",
			"https://api.threatminer.org/v2/domain.php?q="+url+"&rt=5",
			"https://api.certspotter.com/v1/issuances?domain="+url+"&include_subdomains=true&expand=dns_names",
			"https://api.hackertarget.com/hostsearch/?q="+url,
			"https://riddler.io/search/exportcsv?q=pld:"+url,
			"http://index.commoncrawl.org/CC-MAIN-2020-50-index?url=*."+url+"&output=json",
		]
		Y = Pool(12)
		Y.map(self.subdo, api)

	def checkdomain(self, domain):
		try:
			s = socket.gethostbyname(domain)
			http = "http://"+domain
			x = requests.get(http, verify=True, timeout=10)
			rex = re.findall("<title>(.*?)</title>", x.text)[0]
			if rex:
				self.live_subdomain.append([domain, s, str(x.status_code), rex])
			else:
				self.live_subdomain.append([domain, s, "Unknown", "Unknown"])
		except:
			pass
