ShellDlg.cpp
上传用户:cjw5120
上传日期:2022-05-11
资源大小:5032k
文件大小:4k
源码类别:

网络截获/分析

开发平台:

Visual C++

  1. // ShellDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "MyClient.h"
  5. #include "ShellDlg.h"
  6. #include "TcpTran.h"
  7. #include "comm.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /*
  14.  作者:海啸 lyyer English Name: Jack 
  15.   blog:http://lyyer.blog.sohu.com
  16.   website:http://www.cnGSG.com
  17.   海啸网络安全组织
  18. */
  19. CWinThread *pCmdShellThread = NULL;
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CShellDlg dialog
  22. //CmdShell 线程
  23. UINT CmdShellThread(LPVOID lparam)
  24. {
  25. CTcpTran m_tcptran;
  26. COMMAND m_control;
  27. memset(&m_control,0,sizeof(COMMAND));
  28. m_control.wCmd = CMD_CMDSHELL;
  29. CShellDlg *pDlg=(CShellDlg *)lparam;
  30. if(pDlg->m_command=="")
  31. ExitThread(0);//无命令,退出线程
  32. if(pDlg->ClientSocket!=INVALID_SOCKET)
  33. {
  34.     int ret;
  35.     char RecvBuf[1024]={0};    //接收缓冲
  36.     char command[120];
  37.   strcpy(command,pDlg->m_command);  
  38. strcpy(m_control.szCurDir,command);
  39.  
  40. ret=m_tcptran.mysend(pDlg->ClientSocket,(char *)&m_control,sizeof(m_control),0,60);//开启CMDSHELL
  41. while(ret>0)
  42. {
  43. ret=m_tcptran.myrecv(pDlg->ClientSocket,RecvBuf,sizeof (RecvBuf),0,60,0,false); //接收目标数据
  44.             if(ret<=0||RecvBuf[0]==MY_END)
  45. break;
  46. //表示接收到数据
  47. CString current;
  48. pDlg->m_CmdEdit.GetWindowText(current);
  49.     pDlg->m_CmdEdit.SetWindowText(current+RecvBuf);
  50.     memset(RecvBuf,0,sizeof(RecvBuf));  //缓冲清零
  51. pDlg->m_CmdEdit.LineScroll(pDlg->m_CmdEdit.GetLineCount());
  52. }
  53. }
  54. pCmdShellThread = NULL;
  55. return 0;
  56. }
  57. CShellDlg::CShellDlg(CWnd* pParent /*=NULL*/)
  58. : CDialog(CShellDlg::IDD, pParent)
  59. {
  60. //{{AFX_DATA_INIT(CShellDlg)
  61. m_command = _T("");
  62. //}}AFX_DATA_INIT
  63. }
  64. void CShellDlg::DoDataExchange(CDataExchange* pDX)
  65. {
  66. CDialog::DoDataExchange(pDX);
  67. //{{AFX_DATA_MAP(CShellDlg)
  68. DDX_Control(pDX, IDC_EDIT_CMDTEXT, m_CmdEdit);
  69. DDX_Text(pDX, IDC_EDIT_CMDSHELL, m_command);
  70. //}}AFX_DATA_MAP
  71. }
  72. BEGIN_MESSAGE_MAP(CShellDlg, CDialog)
  73. //{{AFX_MSG_MAP(CShellDlg)
  74. ON_WM_CTLCOLOR()
  75. ON_WM_SHOWWINDOW()
  76. ON_BN_CLICKED(IDC_BUTTON_CMDSHELL, OnButtonCmdshell)
  77. //}}AFX_MSG_MAP
  78. END_MESSAGE_MAP()
  79. /////////////////////////////////////////////////////////////////////////////
  80. // CShellDlg message handlers
  81. HBRUSH CShellDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
  82. {
  83. HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
  84. // TODO: Change any attributes of the DC here
  85. if( nCtlColor == CTLCOLOR_EDIT)
  86. {
  87. pDC->SetBkMode(TRANSPARENT);
  88. COLORREF COLOR = RGB(0, 0, 0);
  89. HBRUSH brush = CreateSolidBrush(COLOR); //COLOR是你想设置的颜色 
  90. pDC->SetTextColor(RGB(255, 255, 255));
  91.   return (HBRUSH) brush;
  92. }
  93. // TODO: Return a different brush if the default is not desired
  94. return hbr;
  95. }
  96. BOOL CShellDlg::OnInitDialog()
  97. {
  98. CDialog::OnInitDialog();
  99. SetDlgItemText(IDC_EDIT_CMDSHELL,"net share");
  100. //UpdateData(FALSE);
  101. return TRUE;
  102. }
  103. void CShellDlg::OnShowWindow(BOOL bShow, UINT nStatus) 
  104. {
  105.     m_cmd = "海啸远程控制软件 [ 版本权所有 lyyerv1.0] rn版本权所有 2006-2009 rnCmd Line:rn";
  106. //SetDlgItemText(IDC_EDIT_CMDTEXT,m_cmd);
  107. m_CmdEdit.SetWindowText(m_cmd);
  108. if(pCmdShellThread != NULL)
  109. {
  110.   ::TerminateThread(pCmdShellThread->m_hThread, 0);
  111.   ::WaitForSingleObject(pCmdShellThread->m_hThread, INFINITE);
  112.   CloseHandle(pCmdShellThread->m_hThread);
  113.   pCmdShellThread = NULL;
  114. }
  115. CDialog::OnShowWindow(bShow, nStatus);
  116. }
  117. void CShellDlg::OnButtonCmdshell() 
  118. {
  119. // TODO: Add your control notification handler code here
  120. UpdateData();
  121.     if(pCmdShellThread != NULL)
  122. {
  123.   ::TerminateThread(pCmdShellThread->m_hThread, 0);
  124.   ::WaitForSingleObject(pCmdShellThread->m_hThread, INFINITE);
  125.   CloseHandle(pCmdShellThread->m_hThread);
  126.   pCmdShellThread = NULL;
  127. }
  128. pCmdShellThread = AfxBeginThread(CmdShellThread, (LPVOID)this);
  129. }