httpparse.h

来自「监听分析流量中的http流量」· C头文件 代码 · 共 100 行

H
100
字号
// HttpParse.h: interface for the CHttpParse class.
//
//////////////////////////////////////////////////////////////////////
#include <vector>
#include <string>
#include <windows.h>

#include "public.h"

#if !defined(HSSEC_HttpParse_H)
#define HSSEC_HttpParse_H

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#define BUFFERLINES			30
#define IOBUFFSIZE			1024 * 5
#define HTTP_MAX_PACK		1				//Http最大抓包数
#define MAX_BUFFER_LEN		1024 * 64		//最大缓存长度
#define MIN_BUFFER_LEN		1024			//最小缓存长度

#define HTTP_MAX_SAVE     1

#define IS_HTTP_CLIENT 1			
#define IS_HTTP_SERVER 2			
#define IS_HTTP_ERROR -1

using namespace std;

class CHttpParse  
{
public:
	CHttpParse();
	virtual ~CHttpParse();

public:
	//变量
	char m_pIACBuff[IOBUFFSIZE];			//用于返回Http协商结果文本形式

	//传入的请求命令字
	vector<HTTP_SESSION*>					m_Http_Session_List;		//存放协议分析数据的链表, 用于存放会话

private:
	//变量
	int		m_CurSession;				//会话当前在链表位置

	
public:
	//入口处理分析
	bool Perform(char *pInput, int nBuffLen, UINT uPort, char *src_ip, char *src_mac,
				 char *src_port, char *des_ip, char *des_mac, char *des_port);
	bool IsHttp(UINT uPort, char *src_port, char *des_port);	//用于判断是否是telnet通信;

private:
	//会话分析
	int  FindSession(char *src_ip, char *src_mac, char *src_port, char *des_ip, char *des_mac, char *des_port);
	bool AddSession(char *pInput, char *src_ip, char *src_mac, 
					char *src_port, char *des_ip, char *des_mac, char *des_port);
	bool ParseSession(char *pInput, char *src_ip, char *src_mac, char *src_port, char *des_ip,
						char *des_mac, char *des_port);
	bool CheckClient(char *pInput, char *src_ip, char *src_mac, char *src_port,
						char *des_ip, char *des_mac, char *des_port, HTTP_SESSION *Node);
	int CheckServerOrClient(char *src_ip, char *src_mac, char *src_port, char *des_ip, char *des_mac, char *des_port);  //功能: 判断一个IP包是否是一个Client所发出
	
	bool CheckSessionEnd(char *pInput);		//结束会话
	


	//组装命令字和回显
	bool SessionPro(char *pInput, int nBuffer, 
							char *src_ip, char *des_ip, char *src_port, char *des_port, char *src_mac, char *des_mac);

	bool HttpDomainName(char *pInput, char **pDomainName);
	bool HttpServerRecv(char *pInput, char **pServerRecv);

	bool ConfigNetAddr(unsigned char **pNetAddr, unsigned char *src_ip, int *nLenAddr, char *date);
	bool ConfigEcho(unsigned char *pInput, unsigned char **pEcho, char *date);

	bool AddRawPackList_NetAddr(char *pCmdBuff, int nBuffLen, char *src_ip, char *des_ip, char *src_port, char *des_port, char *src_mac, char *des_mac);
	bool AddRawPackList_Echo(char *pInput, int nBuffLen, char *src_ip, char *des_ip, char *src_port, char *des_port, char *src_mac, char *des_mac);
	
	bool ConfigSessionRecord(vector<HTTP_SESSION*> &Parse_List, int nCurSession, int nLen);
	bool ConfigFileDirectory(vector<HTTP_SESSION*> &Parse_List, int nCurSession, char *strPath, char *strFileName);

	bool SaveLog(char *pBuff, char *pFileName);

	//--------------删除堆内存, 非常重要, 如果有内存泄漏, 这里要重点注意------------------------------------//
	void DelHttpSessionList();

	void ClearSessionRawPack(int iSession);
	void ClearSessionAppPack(int iSession);

	//辅助函数
	bool SetNowTime(char *pCurTime);

};

#endif // !defined(HSSEC_HttpParse_H)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?