def compose_options(options): tcpsoption = "" avail_opt_len = 40 for opt in options: if opt[0] == 'NOP': if avail_opt_len < 1: break nop = tcplib.create_nop() tcpsoption += nop avail_opt_len -= 1 continue if opt[0] == 'MSS': if avail_opt_len < 4: break mssoption = tcplib.create_mss(opt[1]) tcpsoption += mssoption avail_opt_len -= 4 continue if opt[0] == 'WSCALE': if avail_opt_len < 3: break wsoption = tcplib.create_winscale(opt[1]) tcpsoption += wsoption avail_opt_len -= 3 continue if opt[0] == 'SACKOK': if avail_opt_len < 2: break sackok_option = tcplib.create_sackok() tcpsoption += sackok_option avail_opt_len -= 2 continue if opt[0] == 'TIMESTAMP': if avail_opt_len < 10: break tsoption = tcplib.create_timestamp(opt[1], opt[2]) tcpsoption += tsoption avail_opt_len -= 10 continue if opt[0] == 'MP_CAPABLE': length = 20 if opt[3] is not None else 12 if avail_opt_len < length: break mpcap_option = tcplib.create_mpcapable(opt[1], opt[2], opt[3]) tcpsoption += mpcap_option avail_opt_len -= length continue if opt[0] == 'MP_DSS': length = (14 if opt[6] is not None else 0) + (4 if opt[4] is not None else 0) + \ (4 if opt[4] is not None and opt[3] else 0) + (4 if opt[5] else 0) if avail_opt_len < length: break dss_option = tcplib.create_mpdss(opt[1], opt[2], opt[3], opt[4], \ opt[5], opt[6], opt[7]) tcpsoption += dss_option avail_opt_len -= length continue if opt[0] == 'MP_ACK': if avail_opt_len < 10: break dataack_option = tcplib.create_mpack(opt[1]) tcpsoption += dataack_option avail_opt_len -= 10 continue tcpsoption += tcplib.check_padding(tcpsoption) return tcpsoption
def compose_options(options): tcpsoption = "" avail_opt_len = 40 for opt in options: if opt[0] == 'NOP': if avail_opt_len < 1: break nop = tcplib.create_nop() tcpsoption += nop avail_opt_len -= 1 continue if opt[0] == 'MSS': if avail_opt_len < 4: break mssoption = tcplib.create_mss(opt[1]) tcpsoption += mssoption avail_opt_len -= 4 continue if opt[0] == 'WSCALE': if avail_opt_len < 3: break wsoption = tcplib.create_winscale(opt[1]) tcpsoption += wsoption avail_opt_len -= 3 continue if opt[0] == 'SACKOK': if avail_opt_len < 2: break sackok_option = tcplib.create_sackok() tcpsoption += sackok_option avail_opt_len -= 2 continue if opt[0] == 'TIMESTAMP': if avail_opt_len < 10: break tsoption = tcplib.create_timestamp(opt[1], opt[2]) tcpsoption += tsoption avail_opt_len -= 10 continue if opt[0] == 'MP_CAPABLE': if avail_opt_len < 12: break mpcap_option = tcplib.create_mpcapable(opt[1], opt[2]) tcpsoption += mpcap_option avail_opt_len -= 12 continue if opt[0] == 'MP_DATA': if avail_opt_len < 16: break # (Dsn (8 Byte), Dlen (2 Byte), Ssn(4 Byte)) dsn_option = tcplib.create_mpdata(opt[1], opt[2], opt[3]) tcpsoption += dsn_option avail_opt_len -= 16 continue if opt[0] == 'MP_ACK': if avail_opt_len < 10: break dataack_option = tcplib.create_mpack(opt[1]) tcpsoption += dataack_option avail_opt_len -= 10 continue tcpsoption += tcplib.check_padding(tcpsoption) return tcpsoption
MSSval = 512 WSval = 6 TSval = 12345678 SynTsEcr = 0xffff0000 # Initiator's value mssoption = tcplib.create_mss(MSSval) wsoption = tcplib.create_winscale(WSval) tsoption = tcplib.create_timestamp(TSval,0) sackokoption = tcplib.create_sackok() # # mpcapable option # mptcp_token = 0x0D0C0B0A mptcp_isn = 0x0102030405060000 mpcap_option = tcplib.create_mpcapable(mptcp_token, mptcp_isn) # # constants for ip and tcp header # ipid = 0x4321 ipttl = 255 otcpseqno = 0xabcdef tcpseqno = 0xabcdef tcpwindow = 32768 # # special hack parameters # request_hdrdata = 0xa1 request_hdrdata_http = 0xa3