Skip to content

Instantly share code, notes, and snippets.

@DarrenRainey
Last active June 14, 2018 06:39
Show Gist options
  • Save DarrenRainey/02198ce40990c944625d388dafdb1d9f to your computer and use it in GitHub Desktop.
Save DarrenRainey/02198ce40990c944625d388dafdb1d9f to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
int getport(char * unfiltered)
{
char *port = unfiltered;
long val = strtol(port, &port, 10);
return val;
}
void nmapfile(char * file, char *ip, char *hydracmds, int debug)
{
char buffer[2048];
char cmdbuffer[1024]; // TEMPORAY until code can be merged with main hydra source code
FILE *nmaplog = fopen(file,"r");
if(nmaplog == NULL) //
{ //
printf("ERROR: Unable to nmap open file: %s\n",file); // ERROR HANDLING
exit(1); //
} //
// Load file into memory for later processing
while(fgets(buffer, sizeof(buffer), nmaplog) != NULL)
{
if(strstr(buffer,"ssh") && strstr(buffer,"open"))
{
if(debug == 1)
{
printf("SSH DETECTED - PORT: %ld\n",getport(buffer));
}
// RUN HYDRA WITH SSH - TODO use proper hydra source code and functions rather than system calls
snprintf(cmdbuffer, sizeof(cmdbuffer), "hydra %s ssh://%s -s %ld",hydracmds,ip,getport(buffer)); // TEMPORAY until code can be merged with main hydra source code
if(debug == 0) //
{ //
system(cmdbuffer); // TEMPORAY until code can be merged with main hydra source code
} //
//
if(debug == 1) //
{ //
printf("COMMAND BUFFER Contents: %s\n",cmdbuffer); //
} //
}
else if(strstr(buffer,"ftp") && strstr(buffer,"open"))
{
if(debug == 1)
{
printf("FTP DETECTED - PORT: %ld\n",getport(buffer));
}
// RUN HYDRA WITH FTP
snprintf(cmdbuffer, sizeof(cmdbuffer), "hydra %s ftp://%s -s %ld",hydracmds,ip,getport(buffer)); // TEMPORAY until code can be merged with main hydra source code
if(debug == 0)
{
system(cmdbuffer); // TEMPORAY until code can be merged with main hydra source code
}
if(debug == 1)
{
printf("COMMAND BUFFER Contents: %s\n",cmdbuffer);
}
}
}
}
int main(int argc, char *argv[])
{
printf("Code By Darren Rainey - https://GitHub.com/DarrenRainey\n");
int debug = 1; // Set to 1 to see commands without running
if(argc == 4)
{
nmapfile(argv[1],argv[2],argv[3],debug);
}
else
{
printf("Usage %s nmap.log 127.0.0.1, \"hydra options such as -C\" \n",argv[0]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment