Jump to content
JIHAD

C - HTTP BASIC AUTHENTICATION

Recommended Posts

Posted

Folositor pentru facut brute de cpanel.

//JIHAD 2014
//usage: ./http user:password ip port
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include <stdio.h>
#define USERAGENT "JIHAD HTTP AGENT"
#define TABLELEN 63
#define BUFFFERLEN 128

#define ENCODERLEN 4
#define ENCODEROPLEN 0
#define ENCODERBLOCKLEN 3

#define PADDINGCHAR '='
#define BASE64CHARSET "ABCDEFGHIJKLMNOPQRSTUVWXYZ"\
"abcdefghijklmnopqrstuvwxyz"\
"0123456789"\
"+/";
int Base64Encode(char *input, char *output, int oplen);
int encodeblock(char *input, char *output, int oplen);
int Base64Decode(char *input, char *output, int oplen);
int decodeblock(char *input, char *output, int oplen);


int encodeblock(char *input, char *output, int oplen){
int rc = 0, iplen = 0;
char encodedstr[ENCODERLEN + 1] = "";
char encodingtabe[TABLELEN + 1] = BASE64CHARSET;

iplen = strlen(input);
encodedstr[0] = encodingtabe[ input[0] >> 2 ];
encodedstr[1] = encodingtabe[ ((input[0] & 0x03) << 4) |
((input[1] & 0xf0) >> 4) ];
encodedstr[2] = (iplen > 1 ? encodingtabe[ ((input[1] & 0x0f) << 2) |
((input[2] & 0xc0) >> 6) ] : PADDINGCHAR);
encodedstr[3] = (iplen > 2 ? encodingtabe[ input[2] & 0x3f ] : PADDINGCHAR);
strncat(output, encodedstr, oplen-strlen(output));

return rc;
}

int Base64Encode(char *input, char *output, int oplen){
int rc = 0;
int index = 0, ipindex = 0, iplen = 0;
char encoderinput[ENCODERBLOCKLEN + 1] = "";

iplen = strlen(input);
while(ipindex < iplen){
for(index = 0; index < 3; index++){
if(ipindex < iplen){
encoderinput[index] = input[ipindex];
}else{
encoderinput[index] = 0;
}
ipindex++;
}
rc = encodeblock(encoderinput, output, oplen);
}

return rc;
}

int http_auth(char *username,char *hostname, char *port)
{
int rc = 0;
char auth[BUFFFERLEN + 1] = "";
int sock;
struct sockaddr_in server;
char server_reply[2000];
char message[2000];

sock = socket(AF_INET , SOCK_STREAM , 0);
if (sock == -1)
{
return -1;
}
server.sin_addr.s_addr = inet_addr(hostname);
server.sin_family = AF_INET;
server.sin_port = htons( atoi(port) );
if (connect(sock , (struct sockaddr *)&server , sizeof(server)) < 0)
{
return -1;
}
rc = Base64Encode(username, auth, BUFFFERLEN);

sprintf(message,"GET / HTTP/1.1\r\nHost: %s\r\nUser-Agent: %s\r\nAuthorization: Basic %s\r\nConnection: close\r\n\r\n",
hostname, USERAGENT, auth);
send(sock, message , strlen(message), 0);
recv(sock, server_reply , 2000 , 0);
printf(server_reply);
return 0;
}



int main(int argc, char **argv)
{
http_auth(argv[1],argv[2], argv[3]);
}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...