📄 beastscanerdlg.cpp
字号:
this->cTabCtrl.AddTab(&(this->cPortScanDlg),"Port Scan",2);
this->cTabCtrl.SelectTab(0);
}
void CBeastScanerDlg::OnOK()
{
// TODO: 在此添加专用代码和/或调用基类
this->cTabCtrl.SelectNextTab(TRUE);
}
void CBeastScanerDlg::OnNMDblclkListHostInfo(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
*pResult = 0;
if(pNMHDR->code==NM_DBLCLK)
{
int nCurrentSel=this->cListHostInfo.GetSelectionMark();
if(nCurrentSel<0)
{
return ;
}
else
{
if(this->enCurrentScanType==NO_SCAN)
{
// DWORD dwHostIP=ntohl(inet_addr(this->cListHostInfo.GetItemText(nCurrentSel,1).GetBuffer()));
DWORD dwHostIP=ntohl(inet_addr(this->cListHostInfo.GetItemText(nCurrentSel,1).GetBuffer(20)));
this->cTabCtrl.SelectTab(2);
this->cPortScanDlg.dwOriginateIP=dwHostIP;
this->cPortScanDlg.m_OriginateIP.SetAddress(dwHostIP);
this->cPortScanDlg.bSingleIP=TRUE;
this->cPortScanDlg.UpdateData(FALSE);
this->cPortScanDlg.cIPAddressCtrl.EnableWindow(FALSE);
}
else
{
this->MessageBox("It is scaning now,Please try latter.","Attention",MB_OK|MB_ICONSTOP);
}
}
}
}
void CBeastScanerDlg::OnBnClickedPause()
{
// TODO: Add your control notification handler code here
if(this->enCurrentScanType!=NO_SCAN)
{
this->cTabCtrl.EnableWindow();
if(bPause==false)
{
this->cButtonPause.SetWindowText("Resume");
bPause=true;
this->stCurrentState="Scan is Paused.";
this->UpdateData(FALSE);
}
else
{
this->cButtonPause.SetWindowText("Pause");
bPause=false;
this->stCurrentState="Resume Scan";
this->UpdateData(FALSE);
}
}
}
void CBeastScanerDlg::OnBnClickedStop()
{
// TODO: Add your control notification handler code here
if(this->enCurrentScanType!=NO_SCAN)
{
this->enCurrentScanType=NO_SCAN;
this->cTabCtrl.EnableWindow();
this->stCurrentState="Scan is Stoped.";
this->UpdateData(FALSE);
bStop=true;
}
this->cButtonPause.SetWindowText("Pause");
bPause=false;
}
LRESULT CBeastScanerDlg::OnBeginScan(WPARAM enCurrentScanType,LPARAM pThreadParament)
{
if(this->enCurrentScanType==NO_SCAN)
{
if(((ThreadParament*)pThreadParament)->dwOriginalIP>((ThreadParament*)pThreadParament)->dwLastIP||((ThreadParament*)pThreadParament)->dwOriginalPort>((ThreadParament*)pThreadParament)->dwLastPort)
{
this->MessageBox("Set Parament Error ,Check what you set!","Error",MB_OK|MB_ICONERROR);
return 0;
}
bStop=false;
dwCurrentHostNo=0;
dwCurrentPortInfoNo=0;
this->enCurrentScanType=(SCAN_TYPE)enCurrentScanType;
if(!(this->enCurrentScanType!=ARP_SCAN &&this->enCurrentScanType!=ARP_FAST_SCAN &&this->enCurrentScanType!=ICMP_WRONG_PORT_SCAN&&this->enCurrentScanType!=ICMP_IP_REORGANIZATION_SCAN&&this->enCurrentScanType!=ICMP_WRONG_PROTOCOL_SCAN&&this->enCurrentScanType!=ICMP_SCAN))
{
this->cListHostInfo.DeleteAllItems();
}
this->cListPortInfo.DeleteAllItems();
this->cTabCtrl.EnableWindow(FALSE);
this->stCurrentState="Waiting for Scan Finish…………";
this->UpdateData(TRUE);
((ThreadParament*)pThreadParament)->SelectDev=this->SelectDev;
((ThreadParament*)pThreadParament)->dwHostIP=this->dwLocalIP;
((ThreadParament*)pThreadParament)->dwDefaultGateway=this->dwDefaultGateway;
((ThreadParament*)pThreadParament)->dwNetMAsk=this->dwNetMask;
memcpy(((ThreadParament*)pThreadParament)->HostMac,this->bLocalMac,6);
ScanHandler(this->enCurrentScanType,(ThreadParament*)pThreadParament);
}
return 0;
}
LRESULT CBeastScanerDlg::OnHandleUdpScan(WPARAM wparam,LPARAM lparam)
{
if(this->dwCurrentPortInfoNo==0xfffffffe)
{
this->MessageBox("Too many PortInfo!");
return 0;
}
this->cListPortInfo.InsertItem(dwCurrentPortInfoNo,"Udp Scan");
CString Tmp;
Tmp.Format("%u",0xffff&lparam);
in_addr inHostIp;
inHostIp.S_un.S_addr=htonl((DWORD)wparam);
this->cListPortInfo.SetItemText(this->dwCurrentPortInfoNo,1,inet_ntoa(inHostIp));
this->cListPortInfo.SetItemText(this->dwCurrentPortInfoNo,2,Tmp.GetBuffer(10));
if((0xffff0000&lparam)!=0)
{
this->cListPortInfo.SetItemText(this->dwCurrentPortInfoNo,3,"Open/Host not exitst");
}
else
{
this->cListPortInfo.SetItemText(this->dwCurrentPortInfoNo,3,"Closed");
}
this->dwCurrentPortInfoNo++;
return 0;
}
LRESULT CBeastScanerDlg::OnHandleSynScan(WPARAM StateAndPort,LPARAM dwHostIP)
{
if(this->dwCurrentPortInfoNo==0xfffffffe)
{
this->MessageBox("Too many PortInfo!");
return 0;
}
this->cListPortInfo.InsertItem(dwCurrentPortInfoNo,"Tcp Syn Scan");
in_addr inHostIp;
inHostIp.S_un.S_addr=htonl((DWORD)dwHostIP);
CString Tmp;
Tmp.Format("%u",0xffff&StateAndPort);
this->cListPortInfo.SetItemText(this->dwCurrentPortInfoNo,1,inet_ntoa(inHostIp));
this->cListPortInfo.SetItemText(this->dwCurrentPortInfoNo,2,Tmp.GetBuffer(10));
if((0xffff0000&StateAndPort)!=0)
{
this->cListPortInfo.SetItemText(this->dwCurrentPortInfoNo,3,"Open");
}
else
{
this->cListPortInfo.SetItemText(this->dwCurrentPortInfoNo,3,"Closed");
}
this->dwCurrentPortInfoNo++;
return 0;
}
LRESULT CBeastScanerDlg::OnHandleNullScan(WPARAM StateAndPort,LPARAM dwHostIP)
{
if(this->dwCurrentPortInfoNo==0xfffffffe)
{
this->MessageBox("Too many PortInfo!");
return 0;
}
this->cListPortInfo.InsertItem(dwCurrentPortInfoNo,"Tcp Null Scan");
in_addr inHostIp;
inHostIp.S_un.S_addr=htonl((DWORD)dwHostIP);
CString Tmp;
Tmp.Format("%u",0xffff&StateAndPort);
this->cListPortInfo.SetItemText(this->dwCurrentPortInfoNo,1,inet_ntoa(inHostIp));
this->cListPortInfo.SetItemText(this->dwCurrentPortInfoNo,2,Tmp.GetBuffer(10));
this->cListPortInfo.SetItemText(this->dwCurrentPortInfoNo,3,"Closed");
this->dwCurrentPortInfoNo++;
return 0;
}
LRESULT CBeastScanerDlg::OnHandleAckScan(WPARAM StateAndPort,LPARAM dwHostIP)
{
if(this->dwCurrentPortInfoNo==0xfffffffe)
{
this->MessageBox("Too many PortInfo!");
return 0;
}
this->cListPortInfo.InsertItem(dwCurrentPortInfoNo,"Tcp Ack Scan");
in_addr inHostIp;
inHostIp.S_un.S_addr=htonl((DWORD)dwHostIP);
CString Tmp;
Tmp.Format("%u",0xffff&StateAndPort);
this->cListPortInfo.SetItemText(this->dwCurrentPortInfoNo,1,inet_ntoa(inHostIp));
this->cListPortInfo.SetItemText(this->dwCurrentPortInfoNo,2,Tmp.GetBuffer(10));
this->cListPortInfo.SetItemText(this->dwCurrentPortInfoNo,3,"Open");
this->dwCurrentPortInfoNo++;
return 0;
}
LRESULT CBeastScanerDlg::OnHandleFinScan(WPARAM StateAndPort,LPARAM dwHostIP)
{
if(this->dwCurrentPortInfoNo==0xfffffffe)
{
this->MessageBox("Too many PortInfo!");
return 0;
}
this->cListPortInfo.InsertItem(dwCurrentPortInfoNo,"Tcp Fin Scan");
in_addr inHostIp;
inHostIp.S_un.S_addr=htonl((DWORD)dwHostIP);
CString Tmp;
Tmp.Format("%u",0xffff&StateAndPort);
this->cListPortInfo.SetItemText(this->dwCurrentPortInfoNo,1,inet_ntoa(inHostIp));
this->cListPortInfo.SetItemText(this->dwCurrentPortInfoNo,2,Tmp.GetBuffer(10));
this->cListPortInfo.SetItemText(this->dwCurrentPortInfoNo,3,"Closed");
this->dwCurrentPortInfoNo++;
return 0;
}
LRESULT CBeastScanerDlg::OnFinishScan(WPARAM enCurrentScanType,LPARAM pThreadParament)
{
if(this->enCurrentScanType!=NO_SCAN)
{
if(bStop==true)
{
bStop=false;
this->stCurrentState="Scan Stoped.";
}
else
{
this->stCurrentState="Scan Finished.";
}
this->cTabCtrl.EnableWindow();
this->enCurrentScanType=NO_SCAN;
this->UpdateData(FALSE);
}
this->cButtonPause.SetWindowText("Pause");
bPause=false;
return 0;
}
LRESULT CBeastScanerDlg::OnAddHostInfo(WPARAM ScanType/*0: ARP ;1 Icmp*/, LPARAM dwHostIP)
{
if(dwCurrentHostNo==0xFFFFFFFe)
{
this->MessageBox("Too many Host!");
return 0;
}
if(ScanType==0)
{
this->cListHostInfo.InsertItem(dwCurrentHostNo,"ARP");
}
else
{
this->cListHostInfo.InsertItem(dwCurrentHostNo,"ICMP");
}
in_addr inHostIp;
inHostIp.S_un.S_addr=htonl((DWORD)dwHostIP);
this->cListHostInfo.SetItemText(dwCurrentHostNo,1,inet_ntoa(inHostIp));
dwCurrentHostNo++;
return 0;
}
LRESULT CBeastScanerDlg::OnUpdataLog(WPARAM wparam,LPARAM lparam)
{
this->stCurrentState=(char *)wparam;
this->UpdateData(FALSE);
return 0;
}
LRESULT CBeastScanerDlg::OnHandleConnectScan(WPARAM wparam,LPARAM lparam)
{
if(bPause||bStop)
{
return 0;
}
WORD wEvent = WSAGETSELECTEVENT (lparam) ; // ie, LOWORD
WORD wError = WSAGETSELECTERROR (lparam) ; // ie, HIWORD
SOCKET theSocket=(SOCKET)wparam;
if(wEvent==FD_CONNECT)
{
if(!wError)
{
if(this->dwCurrentPortInfoNo==0xfffffffe)
{
this->MessageBox("Too many PortInfo!");
return 0;
}
SOCKADDR thePeerName;
int size=sizeof(sockaddr);
getpeername(theSocket,&thePeerName,&size);
if(closesocket(theSocket)==0)
{
this->cListPortInfo.InsertItem(dwCurrentPortInfoNo,"Tcp Connect Scan");
CString Tmp;
Tmp.Format("%u",htons(((sockaddr_in*)(&thePeerName))->sin_port));
this->cListPortInfo.SetItemText(this->dwCurrentPortInfoNo,1,inet_ntoa(((sockaddr_in*)(&thePeerName))->sin_addr));
this->cListPortInfo.SetItemText(this->dwCurrentPortInfoNo,2,Tmp.GetBuffer(10));
this->cListPortInfo.SetItemText(this->dwCurrentPortInfoNo,3,"Open");
this->dwCurrentPortInfoNo++;
return 1;
}
}
}
closesocket(theSocket);
return 0;
}
void CBeastScanerDlg::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
pcap_freealldevs(alldevs);
}
CBeastScanerDlg::~CBeastScanerDlg()
{
bStop=true;
while(dwCurrentThreadNo!=0)
{
Sleep(100);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -