-
-
Save ihebski/c499c7346a7bd71157aa555bc8309f54 to your computer and use it in GitHub Desktop.
store subdomains into sqlite db
This file contains hidden or 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
#!/usr/bin/env python3 | |
# @ih3bski | |
from flask import Flask | |
from flask_sqlalchemy import SQLAlchemy | |
import uuid | |
from loguru import logger | |
import sys | |
app = Flask(__name__) | |
# Change the default db path | |
dbname = "bb_record" | |
dbpath = "/tmp" | |
# SQLAlchemy config/Disable warnings for a clean output $_$ | |
app.config['SQLALCHEMY_DATABASE_URI'] = f'sqlite:///{dbpath}/{dbname}.sqlite' | |
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False | |
db = SQLAlchemy(app) | |
stats = logger.level("STATS", no=38, color="<yellow>", icon="๐") | |
Counter = 0 | |
# Model -> T.B changed | |
class Target(db.Model): | |
__tablename__ = 'Target' | |
id = db.Column(db.Text, primary_key=True) | |
subdomain = db.Column(db.Text) | |
def __init__(self,id,subdomain): | |
self.subdomain = subdomain | |
self.id = id | |
db.create_all() | |
def save(subdomain): | |
global Counter | |
if db.session.query(Target.id).filter_by(subdomain=subdomain).scalar() is None : | |
db.session.add(Target(str(uuid.uuid4()),subdomain)) | |
db.session.commit() | |
Counter += 1 | |
logger.log('INFO',f'[+] {subdomain} added to database') | |
else: | |
logger.log('ERROR',f'[-] {subdomain} already exists') | |
def search(subdomain): | |
sub = db.session.query(Target).filter(Target.subdomain.like(f"%{subdomain}%")).all() | |
if sub : | |
for row in sub: | |
logger.log('INFO',row.subdomain) | |
logger.log("STATS", f'We have found {len(sub)} subdomains ! Happy Hacking $_$') | |
else: | |
logger.log('WARNING',f'[-] {subdomain} NOT FOUND.') | |
def main(): | |
# use stdin if it's full | |
if not sys.stdin.isatty(): | |
for subdomains in sys.stdin: | |
save(subdomains.strip()) | |
logger.log("STATS", f'{Counter} Bulk added ^_^ !') | |
# read subdomain as argument | |
else: | |
if len(sys.argv) > 1: | |
search(sys.argv[1]) | |
else: | |
print("Usage:\n Store new subdomains : cat targets | python3 db.py \n Search subdomains: python3 db.py <domain>") | |
if __name__ == '__main__': | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Welcome ๐ thrilled to hear that, you can use tee
db site.com 2>&1 | tee -a db-results.txt
For a cleaner results, to extract subdomains only without the debug output
db site.com 2>&1 | cut -d' ' -f 12 | tee -a db-results.txt