通过1433获取SQL Server版本(源代码)

论坛 期权论坛 脚本     
已经匿名di用户   2022-5-29 19:37   1874   0

http://www.sqlsecurity.com/的Chip Andrews发布的SQL ver,原来是用C#写的,偶稍稍作了下修改,顺便学习一下Unix下Socket编程。:-)

编译环境:FreeBSD 5.2 (i386)

(win32的程序可以在这里下载

http://www.xfocus.net/tools/200408/795.html

#include
#include



int main(int argc,char *argv[])
{
struct sockaddr_in srt_addr;
int ssocket; //the socket
int nret; //the return value
int nport = 1433;
char szbuf1[] = {
0x12,0x01,0x00,0x34,0x00,0x00,0x00,0x00,
0x00,0x00,0x15,0x00,0x06,0x01,0x00,0x1b,
0x00,0x01,0x02,0x00,0x1c,0x00,0x0c,0x03,
0x00,0x28,0x00,0x04,0xff,0x08,0x00,0x01,
0x55,0x00,0x00,0x00,0x4d,0x53,0x53,0x51,
0x4c,0x53,0x65,0x72,0x76,0x65,0x72,0x00,
0x04,0x08,0x00,0x00};
char szbuf2[1024] = {0};
int nrecvlen = 1024;

if (argc < 2 || argc >3)
{
printf("/n/n[+]usage:%s targetip sqlport/n/n",argv[0]);
printf("code by yztgx@hotmail.com/n");
exit(1);
}

printf("/n/n[+]code by yztgx@hotmail.com/n");
printf("[+]Author: Chip Andrews/n");
printf("[+]reference:http://www.sqlsecurity.com/n");
printf("[+]my blog:http://blog.csdn.net/yztgx/n/n/n");



if (argc == 3)
{
nport = atoi(argv[2]);
if (!nport)
nport = 1433;
}
else
nport = 1433;
srt_addr.sin_family = AF_INET;
srt_addr.sin_port = htons(nport);
srt_addr.sin_addr.s_addr = inet_addr(argv[1]);

ssocket = socket(AF_INET,SOCK_STREAM,0);
if (ssocket < 0)
{
perror("create socket error/n");
exit(1);
}

nret = connect(ssocket,(struct sockaddr *)&srt_addr,sizeof(srt_addr));
if (nret)
{
perror("can't connect the port/n");
exit(1);
}

nret = send(ssocket,szbuf1,sizeof(szbuf1),0);
if (nret == -1)
{
perror("send date error/n");
exit(1);
}

nret = recv(ssocket,szbuf2,nrecvlen,0);
if (nret == -1)
{
perror("recv date error/n");
exit(1);
}

printf("[*]sql ver is:%d.%d.%d/n/nfinish!/n",
(unsigned char)szbuf2[29],
(unsigned char)(szbuf2[30]),
(unsigned char)(szbuf2[31])*256+(unsigned char)szbuf2[32]);

close(ssocket);

return 0;
}


分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:81
帖子:4969
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP