54 CAMsg::printMsg(LOG_DEBUG,
"Starting to capture packets for replay attack.\n");
77 CAMsg::printMsg(LOG_DEBUG,
"CALocalProxy main: init() returned success\n");
80 CAMsg::printMsg(LOG_DEBUG,
"CAMix local proxy: loop() returned, maybe connection lost.\n");
104 #if defined(REPLAY_DETECTION)&&!defined(_WIN32)
110 UINT8 strTarget[255];
142 delete pSocketAddrIn;
143 pSocketAddrIn = NULL;
157 delete pSocketAddrIn;
158 pSocketAddrIn = NULL;
160 UINT8 strTarget[255];
215 #ifdef __BUILD_AS_SHADOW_PLUGIN__
222 bool bHaveSocks=(socksPort!=0xFFFF);
239 unsigned uCapturedChannel = 0;
259 CAMsg::printMsg(LOG_DEBUG,
"Replaying packet #%d: %X %X %X %X\n", (i+1), *pMixPacket->
data, *(pMixPacket->
data+1), *(pMixPacket->
data+2), *(pMixPacket->
data+3));
262 CAMsg::printMsg(LOG_CRIT,
"Mux-Channel Sending Data Error - Exiting!\n");
264 goto MIX_CONNECTION_ERROR;
287 CAMsg::printMsg(LOG_DEBUG,
"Accept Error - Connection from Browser!\n");
298 CAMsg::printMsg(LOG_DEBUG,
"Create new ciphers for new channel - pointer is: %p\n", newCipher);
300 pSocketList->
add(newSocket,newCipher);
301 pSocketGroup->
add(*newSocket);
324 pSocketList->
add(newSocket,newCipher);
325 pSocketGroup->
add(*newSocket);
335 CAMsg::printMsg(LOG_CRIT,
"Mux-Channel Receiving Data Error - Exiting!\n");
337 goto MIX_CONNECTION_ERROR;
363 if(pMixPacket->
channel == uCapturedChannel)
378 CAMsg::printMsg(LOG_DEBUG,
"Sending Data to Browser (%u bytes)!\n",truelen);
410 while(tmpCon!=NULL&&countRead>0)
425 pSocketGroup->
remove(*tmpSocket);
476 #ifdef WITH_TIMESTAMP
535 CAMsg::printMsg(LOG_DEBUG,
"Captured channel-open packet: %X %X %X %X\n", *pMixPacket->
data, *(pMixPacket->
data+1), *(pMixPacket->
data+2), *(pMixPacket->
data+3));
537 uCapturedChannel = pMixPacket->
channel;
541 CAMsg::printMsg(LOG_DEBUG,
"Captured data packet: %X %X %X %X\n", *pMixPacket->
data, *(pMixPacket->
data+1), *(pMixPacket->
data+2), *(pMixPacket->
data+3));
547 CAMsg::printMsg(LOG_DEBUG,
"Storage full, stopping to capture packets.\n");
553 CAMsg::printMsg(LOG_CRIT,
"Mux-Channel Sending Data Error - Exiting!\n");
555 goto MIX_CONNECTION_ERROR;
564 MIX_CONNECTION_ERROR:
608 CAMsg::printMsg(LOG_INFO,
"Login process and key exchange started...\n");
618 DOMElement* root=doc->getDocumentElement();
619 DOMElement* elemVersion=NULL;
621 UINT8 strVersion[255];
626 CAMsg::printMsg(LOG_INFO,
"XML MixProtocolVersion value:%s\n",strVersion);
628 if(tmpLen==3&&memcmp(strVersion,
"0.4",3)==0)
634 else if(tmpLen==3&&memcmp(strVersion,
"0.3",3)==0)
639 else if(tmpLen==3&&memcmp(strVersion,
"0.2",3)==0)
644 else if(tmpLen==4&&memcmp(strVersion,
"0.10",4)==0)
666 DOMElement* elemMixes=NULL;
690 DOMNode* child=elemMixes->getLastChild();
692 while(child!= NULL&&chainlen>0)
694 if(
equals(child->getNodeName(),
"Mix"))
696 DOMNode* nodeKey=child->getFirstChild();
704 DOMNode* tmpNode = NULL;
721 if(strcmp(
"0.6",(
char*)tmpBuff)==0)
730 DOMElement* nodeDownstreamSendMe=NULL;
741 child=child->getPreviousSibling();
765 memcpy(oPacket.
data,
"KEYPACKET",9);
766 memcpy(oPacket.
data+9,keys,32);
773 const char* XML_HEADER=
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
774 const UINT32 XML_HEADER_SIZE=strlen(XML_HEADER);
775 const char* XML_JAP_KEY_TEMPLATE=
"<JAPKeyExchange version=\"0.1\"><LinkEncryption>%s</LinkEncryption><MixEncryption>%s</MixEncryption><AccessControlCredential>%s</AccessControlCredential></JAPKeyExchange>";
784 UINT8 outBuffLinkKey[512];
787 outBuffLinkKey[outlenLinkKey]=0;
796 UINT8 outBuffMixKey[512];
799 outBuffMixKey[outlenMixKey]=0;
803 outBuffMixKey[outlenMixKey]=0;
804 UINT8 strCredential[512];
805 UINT32 strCredentialLen=512;
806 strCredential[0] = 0;
809 sprintf((
char*)buff,XML_JAP_KEY_TEMPLATE,outBuffLinkKey,outBuffMixKey,strCredential);
812 UINT16 size2=htons((
UINT16)(encbufflen+XML_HEADER_SIZE));
857 CAMsg::printMsg(LOG_INFO,
"Login process and key exchange finished!\n");
void SIGUSR2_handler(int signum)
void SIGUSR1_handler(int signum)
SYMCHANNELCIPHER_ALGORITHM
SINT32 getDOMElementValue(const DOMNode *const pElem, UINT8 *value, UINT32 *valuelen)
Returns the content of the text node(s) under elem as null-terminated C String.
bool equals(const XMLCh *const e1, const char *const e2)
SINT32 sSleep(UINT32 sec)
Sleeps sec Seconds.
XERCES_CPP_NAMESPACE::DOMDocument * parseDOMDocument(const UINT8 *const buff, UINT32 len)
Parses a buffer containing an XML document and returns this document.
SINT32 getRandom(UINT32 *val)
Gets 32 random bits.
SINT32 getDOMChildByName(const DOMNode *pNode, const char *const name, DOMElement *&child, bool deep)
SINT32 getDOMElementAttribute(const DOMNode *const elem, const char *attrName, UINT8 *value, UINT32 *len)
SINT32 encryptXMLElement(DOMNode *node, CAASymCipher *pRSA)
The resulting encrypted xml struct is as follows:
#define MIX_CASCADE_PROTOCOL_VERSION_0_3
#define MIX_CASCADE_PROTOCOL_VERSION_0_2
#define MIX_CASCADE_PROTOCOL_VERSION_0_1_0
#define MIX_CASCADE_PROTOCOL_VERSION_0_4
#define FLOW_CONTROL_SENDME_SOFT_LIMIT
SINT32 encryptOAEP(const UINT8 *from, UINT32 fromlen, UINT8 *to, UINT32 *len)
Encrypts one block of plain text using OAEP padding.
SINT32 encrypt(const UINT8 *from, UINT8 *to)
Encrypts exactly one block which is stored in from.
static SINT32 encode(const UINT8 *in, UINT32 len, UINT8 *out, UINT32 *outlen)
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff...
SINT32 receiveFully(UINT8 *buff, UINT32 len)
Receives all len bytes.
SINT32 getCredential(UINT8 *name, UINT32 len)
SINT32 getMixHost(UINT8 *host, UINT32 len)
CAListenerInterface * getListenerInterface(UINT32 nr)
UINT16 getSOCKSServerPort()
static CACmdLnOptions * getOptions()
CASocketAddr * getAddr() const
static bool bCapturePackets
UINT32 m_MixCascadeProtocolVersion
UINT32 m_SymChannelEncryptedKeySize
bool m_bWithEnhancedChannelEncryption
bool m_bWithNewFlowControl
bool m_bWithFirstMixSymmetric
SYMCHANNELCIPHER_ALGORITHM * m_arSymCipherAlgorithms
static int iCapturedPackets
UINT32 m_SymChannelKeySize
UINT32 m_nFlowControlDownstreamSendMe
static bool bReplayPackets
CASymChannelCipher * m_pSymCipher
SINT32 processKeyExchange(UINT8 *buff, UINT32 size)
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.
SINT32 close()
Closes the underlying socket.
SINT32 receive(MIXPACKET *pPacket)
Receives a whole MixPacket.
SINT32 connect(CASocketAddr &psa)
SINT32 setSendKey(UINT8 *key, UINT32 keyLen)
SINT32 setReceiveKey(UINT8 *key, UINT32 keyLen)
SINT32 send(MIXPACKET *pPacket)
Sends a MixPacket over the Network.
SINT32 setCipher(SYMCHANNELCIPHER_ALGORITHM algCipher)
This class represents a socket address for Internet (IP) connections.
SINT32 setAddr(const UINT8 *szIP, UINT16 port)
Sets the address to szIP and port.
UINT16 getPort() const
Returns the port value of the address.
SINT32 remove(CASocket &s)
bool isSignaled(CASocket &s)
SINT32 add(CASocket &s)
Adds the socket s to the socket group.
virtual SINT32 receive(UINT8 *buff, UINT32 len)
Will receive some bytes from the socket.
virtual SINT32 listen(const CASocketAddr &psa)
Starts listening on address psa.
virtual SINT32 send(const UINT8 *buff, UINT32 len)
Sends some data over the network.
virtual SINT32 setRecvBuff(UINT32 r)
virtual SINT32 setReuseAddr(bool b)
virtual SINT32 sendFully(const UINT8 *buff, UINT32 len)
Sends all data over the network.
virtual SINT32 setSendBuff(SINT32 r)
Returns < 0 on error, otherwise the new sendbuffersize (which may be less than r)
virtual SINT32 accept(CASocket &s)
Accepts a new connection.
virtual SINT32 getLocalPort()
SINT32 add(CASocket *pSocket, CASymChannelCipher **pCiphers)
Add a new channel to the channel-list.
SINT32 addSendMeCounter(HCHANNEL in, SINT32 value)
CASocket * remove(HCHANNEL id)
SINT32 get(HCHANNEL in, CONNECTION *out)
Gets a copy of an entry form the channel-list.
CONNECTION * getFirst()
Gets the first entry of the channel-list.
CONNECTION * getNext()
Gets the next entry of the channel-list.
static SYMCHANNELCIPHER_ALGORITHM getAlgIDFromString(UINT8 *strAlgID)
static CASymChannelCipher * createCipher(SYMCHANNELCIPHER_ALGORITHM alg)
virtual bool isKeyValid()=0
virtual SINT32 setKeys(const UINT8 *key, UINT32 keysize)=0
Sets the keys for crypt1() and crypt2() either to the same key (if keysize==KEY_SIZE) or to different...
virtual SINT32 setIV2(const UINT8 *p_iv)=0
Sets iv2 to p_iv.
virtual SINT32 crypt2(const UINT8 *in, UINT8 *out, UINT32 len)=0
virtual SINT32 setKey(const UINT8 *key)=0
Sets the keys for crypt1() and crypt2() to the same key.
virtual SINT32 setIVs(const UINT8 *p_iv)=0
Sets iv1 and iv2 to p_iv.
virtual SINT32 crypt1(const UINT8 *in, UINT8 *out, UINT32 len)=0
CASymChannelCipher ** pCiphers
UINT32 currentSendMeCounter
struct t_MixPacketPayload payload
#define MIX_PAYLOAD_SOCKS
#define NEW_FLOW_CONTROL_FLAG