问题描述
我有一个客户端程序,其hStdInput,hStdOutput和hStdError被重定向到套接字。
如果我使用N etcat 实用程序用于windows我可以得到远程连接,可以输入命令。
下面的命令工作正常:
nc -v -l -p 4444
我想写自己的工具。
我从网站下面获得了Netcat代码,
主窗口函数位于 doexec.c
但是 代码使用下面的CreteProcess(),因为变量 pr00gie = NULL;
extern char * pr00gie = NULL;
si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
si.hStdInput = ShellStdinPipeHandle;
si.hStdOutput = ShellStdoutPipeHandle;
DuplicateHandle(GetCurrentProcess(),ShellStdoutPipeHandle,
GetCurrentProcess(),& si.hStdError,
DUPLICATE_SAME_ACCESS,TRUE,0);
if(CreateProcess(NULL,pr00gie,NULL,NULL,TRUE,0,NULL,NULL,& si,& ProcessInformation))
{
ProcessHandle = ProcessInformation。 hProcess;
CloseHandle(ProcessInformation.hThread);
}
else
printf("无法执行shell,CreateProcess()=%d中的错误",GetLastError());
我无法找到我想要开始的过程!
如果客户端I / O句柄被重定向到套接字,send()和recv()发送到套接字并获取结果的方法是什么?
我尝试了send(),recv,ReadFile(),WriteFile()函数。但是没有用。
我想开始哪个程序?我试过"CMD"但没有帮助。
我应该遵循什么逻辑?
请帮帮我。
I have a client program whose hStdInput, hStdOutput and hStdError are redirected to socket.
If I use Netcat utility for windows I could get the remote connection and could enter commands.
Below command works perfectly:
nc -v -l -p 4444
I want to write my own tool.
I got the Netcat code from below site,
Download source code for Netcat.
The main windows functions are in doexec.c
But the code uses below CreteProcess() which always fail because the variable pr00gie = NULL;
extern char * pr00gie = NULL; si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; si.hStdInput = ShellStdinPipeHandle; si.hStdOutput = ShellStdoutPipeHandle; DuplicateHandle(GetCurrentProcess(), ShellStdoutPipeHandle, GetCurrentProcess(), &si.hStdError, DUPLICATE_SAME_ACCESS, TRUE, 0); if (CreateProcess(NULL, pr00gie, NULL, NULL, TRUE, 0, NULL, NULL, &si, &ProcessInformation)) { ProcessHandle = ProcessInformation.hProcess; CloseHandle(ProcessInformation.hThread); } else printf("Failed to execute shell, error in CreateProcess() = %d", GetLastError());
I couldn't find out which process I wanna start!
What is the method to send() and recv() to the socket and get the result if the clients I/O handles are redirected to socket?
I tried send(), recv, ReadFile(), WriteFile() functions. But didn't work.
Which process I wanna start? I tried "CMD" but didn't help.
What is the logic should I follow?
Please help me.
这篇关于“Netcat -l -p 4444”背后的逻辑是什么? ?如果客户端I / O处理重定向到SOCKET,它如何向/从客户端发送和回收数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!