Beispiel #1
0
def allSearch():
    form = AllSearchForm(request.form)
    # set values
    page = request.form['page']
    rawIpOne = request.form['rawIpOne']
    PortOne = request.form['PortOne']
    rawIpTwo = request.form['rawIpTwo']
    portTwo = request.form['portTwo']
    round_number = request.form['round_number']

    if (form.PortOne.data is None) or (form.portTwo.data is None)or (form.round_number.data is None):
        return redirect(url_for('allSearchInput'))

    ipOne = IpParser(str(rawIpOne))
    ipTwo = IpParser(str(rawIpTwo))

    if (ipOne is -1) or (ipTwo is -1):
        return redirect(url_for('allSearchInput'))

    TcpList = []
    UdpList = []

    #page set
    if int(page) > 1:
        BackPage = int(page) - 1
    else:
        BackPage = int(page)
    FrontPage = int(page) + 1

    #time Set
    Time_Sql = "select * from round_time where round_number = " + str(round_number)

    Time_set = db.engine.execute(Time_Sql)

    if Time_set.rowcount < 1:
        return redirect(url_for('allSearchInput'))

    Time_Set = Time_set.first()

    Time_Start = Time_Set.round_start
    Time_End = Time_Set.round_end

    #SQLs
    searchUdpSQL = 'select * from udp_ip_packet natural join raw_packet where '+'((src_ip = cast('+str(hex(ipOne))+' as binary(4)) and src_port = '+str(PortOne)+' and dst_ip = cast('+str(hex(ipTwo))+' as binary(4)) and dst_port = '+str(portTwo)+') or (src_ip = cast('+str(hex(ipTwo))+' as binary(4)) and src_port = '+str(portTwo)+' and dst_ip = cast('+str(hex(ipOne))+' as binary(4)) and dst_port = '+str(PortOne)+')) and (packet_time between '+"'"+str(Time_Start)+"' and '"+str(Time_End)+"') "+'Limit ' + str(10*(int(page) - 1)) + ', 10'

    searchTcpSQL = 'select * from tcp_ip_packet natural join raw_packet where '+'((src_ip = cast('+str(hex(ipOne))+' as binary(4)) and src_port = '+str(PortOne)+' and dst_ip = cast('+str(hex(ipTwo))+' as binary(4)) and dst_port = '+str(portTwo)+') or (src_ip = cast('+str(hex(ipTwo))+' as binary(4)) and src_port = '+str(portTwo)+' and dst_ip = cast('+str(hex(ipOne))+' as binary(4)) and dst_port = '+str(PortOne)+')) and (packet_time between '+"'"+str(Time_Start)+"' and '"+str(Time_End)+"') "+'Limit ' + str(10*(int(page) - 1)) + ', 10'


    tcp_pack = db.engine.execute(searchTcpSQL)
    udp_pack = db.engine.execute(searchUdpSQL)

    for foundTcp in tcp_pack:
        # tcp_header hex
        tcp_headerInt = ''
        for ToHex in foundTcp.tcp_header:
            tcp_headerInt = tcp_headerInt + hex(ord(ToHex)) + ' '
        tcp_headerInt = tcp_headerInt[:-1]

        # ip_header hex
        ip_headerInt = ''
        for ToHex in foundTcp.ip_header:
            ip_headerInt = ip_headerInt + hex(ord(ToHex)) + ' '
        ip_headerInt = ip_headerInt[:-1]

        # src_ip str
        src_ipInt = ''
        for ToHex in foundTcp.src_ip:
            src_ipInt = src_ipInt + str(ord(ToHex)) + '.'
        src_ipInt = src_ipInt[:-1]

        # dst_ip str
        dst_ipInt = ''
        for ToHex in foundTcp.dst_ip:
            dst_ipInt = dst_ipInt + str(ord(ToHex)) + '.'
        dst_ipInt = dst_ipInt[:-1]

        # payload_data hex
        hex_str = ''
        for ToHex in foundTcp.payload_data:
            hex_str = hex_str + hex(ord(ToHex)) + ' '
        hex_str = hex_str[:-1]

        # payload_data ascii
        asc_str = ''
        asc_str = binToAsc(foundTcp.payload_data)

        TcpList.append([foundTcp, src_ipInt, dst_ipInt, hex_str, asc_str, ip_headerInt, tcp_headerInt])

    for foundUdp in udp_pack:
        # ip_header hex
        ip_headerInt = ''
        for ToHex in foundUdp.ip_header:
            ip_headerInt = ip_headerInt + hex(ord(ToHex)) + ' '
        ip_headerInt = ip_headerInt[:-1]

        # src_ip str
        src_ipInt = ''
        for ToHex in foundUdp.src_ip:
            src_ipInt = src_ipInt + str(ord(ToHex)) + '.'
        src_ipInt = src_ipInt[:-1]

        # dst_ip str
        dst_ipInt = ''
        for ToHex in foundUdp.dst_ip:
            dst_ipInt = src_ipInt + str(ord(ToHex)) + '.'

        dst_ipInt = dst_ipInt[:-1]

        # payload_data hex
        hex_str = ''
        for ToHex in foundUdp.payload_data:

            hex_str = hex_str + hex(ord(ToHex)) + ' '
        hex_str = hex_str[:-1]

        # payload_data ascii
        asc_str = ''
        asc_str = binToAsc(foundUdp.payload_data)

        UdpList.append([foundUdp, src_ipInt, dst_ipInt, hex_str, asc_str, ip_headerInt])

    return render_template('allSearch.html', title='allSearch', form=form, TcpList=TcpList, UdpList=UdpList, BackPage=BackPage, FrontPage=FrontPage, rawIpTwo=rawIpTwo, portTwo=portTwo, rawIpOne=rawIpOne, PortOne=PortOne, page=page, round_number=round_number)
Beispiel #2
0
def srcIpSearch():
    form = SrcIpSearchForm(request.form)
    page = request.form['page']

    if form.src_port.data is None:
        return redirect(url_for('srcIpSearchInput'))

    #for parameter
    src_ip = str(form.src_ip.data)

    src_port = str(form.src_port.data)

    TcpList = []
    UdpList = []

    #page set
    if int(page) > 1:
        BackPage = int(page) - 1
    else:
        BackPage = int(page)
    FrontPage = int(page) + 1
    
    tsql = 'select * from tcp_ip_packet where src_ip = '
    tarIp = IpParser(form.src_ip.data)

    if tarIp is -1:
        return redirect(url_for('srcIpSearchInput'))

    tsql = tsql + 'cast(' + str(hex(tarIp))+ ' as binary(4)) and src_port = ' + str(form.src_port.data) +  ' Limit ' + str(10*(int(page) - 1)) + ', 10'
    tcp_pack = db.engine.execute(tsql)
        
    for foundTcp in tcp_pack:
        # tcp_header hex
        tcp_headerInt = ''
        for ToHex in foundTcp.tcp_header:
            tcp_headerInt = tcp_headerInt + hex(ord(ToHex)) + ' '
        tcp_headerInt = tcp_headerInt[:-1]

        # ip_header hex
        ip_headerInt = ''
        for ToHex in foundTcp.ip_header:
            ip_headerInt = ip_headerInt + hex(ord(ToHex)) + ' '
        ip_headerInt = ip_headerInt[:-1]

        # src_ip str
        src_ipInt = ''
        for ToHex in foundTcp.src_ip:
            src_ipInt = src_ipInt + str(ord(ToHex)) + '.'
        src_ipInt = src_ipInt[:-1]

        # dst_ip str
        dst_ipInt = ''
        for ToHex in foundTcp.dst_ip:
            dst_ipInt = dst_ipInt + str(ord(ToHex)) + '.'
        dst_ipInt = dst_ipInt[:-1]

        # payload_data hex
        hex_str = ''
        for ToHex in foundTcp.payload_data:
            hex_str = hex_str + hex(ord(ToHex)) + ' '
        hex_str = hex_str[:-1]

        # payload_data ascii
        asc_str = ''
        asc_str = binToAsc(foundTcp.payload_data)

        TcpList.append([foundTcp, src_ipInt, dst_ipInt, hex_str, asc_str, ip_headerInt, tcp_headerInt])

    usql = 'select * from udp_ip_packet where src_ip = '
    usql = usql + 'cast(' + str(hex(tarIp))+ ' as binary(4)) and src_port = ' + str(form.src_port.data) +  ' Limit ' + str(10*(int(page) - 1)) + ', 10'
    udp_pack = db.engine.execute(usql)
        
    for foundUdp in udp_pack:
        # ip_header hex
        ip_headerInt = ''
        for ToHex in foundUdp.ip_header:
            ip_headerInt = ip_headerInt + hex(ord(ToHex)) + ' '
        ip_headerInt = ip_headerInt[:-1]

        # src_ip str
        src_ipInt = ''
        for ToHex in foundUdp.src_ip:
            src_ipInt = src_ipInt + str(ord(ToHex)) + '.'
        src_ipInt = src_ipInt[:-1]

        # dst_ip str
        dst_ipInt = ''
        for ToHex in foundUdp.dst_ip:
            dst_ipInt = dst_ipInt + str(ord(ToHex)) + '.'
        dst_ipInt = dst_ipInt[:-1]

        # payload_data hex
        hex_str = ''
        for ToHex in foundUdp.payload_data:
            hex_str = hex_str + hex(ord(ToHex)) + ' '
        hex_str = hex_str[:-1]

        # payload_data ascii
        asc_str = ''
        asc_str = binToAsc(foundUdp.payload_data)

        UdpList.append([foundUdp, src_ipInt, dst_ipInt, hex_str, asc_str, ip_headerInt])
    return render_template('srcIpSearch.html', title='srcIpSearch', form=form, TcpList=TcpList, UdpList=UdpList, BackPage=BackPage, FrontPage=FrontPage, src_ip=src_ip, src_port=src_port, page=page)
Beispiel #3
0
def deepSearch():
    # set values
    page = request.form['page']
    rawIpOne = request.form['src_ip']
    PortOne = request.form['src_port']
    rawIpTwo = request.form['dst_ip']
    portTwo = request.form['dst_port']
    pack_id = request.form['packet_id']

    ipOne = IpParser(str(rawIpOne))
    ipTwo = IpParser(str(rawIpTwo))

    TcpList = []
    UdpList = []

    #page set
    if int(page) > 1:
        BackPage = int(page) - 1
    else:
        BackPage = int(page)
    FrontPage = int(page) + 1

    #SQLs
    searchUdpSQL = 'select * from udp_ip_packet where '+'(src_ip = cast('+str(hex(ipOne))+' as binary(4)) and src_port = '+str(PortOne)+' and dst_ip = cast('+str(hex(ipTwo))+' as binary(4)) and dst_port = '+str(portTwo)+') or (src_ip = cast('+str(hex(ipTwo))+' as binary(4)) and src_port = '+str(portTwo)+' and dst_ip = cast('+str(hex(ipOne))+' as binary(4)) and dst_port = '+str(PortOne)+')'+' Limit ' + str(10*(int(page) - 1)) + ', 10'

    searchTcpSQL = 'select * from tcp_ip_packet where '+'(src_ip = cast('+str(hex(ipOne))+' as binary(4)) and src_port = '+str(PortOne)+' and dst_ip = cast('+str(hex(ipTwo))+' as binary(4)) and dst_port = '+str(portTwo)+') or (src_ip = cast('+str(hex(ipTwo))+' as binary(4)) and src_port = '+str(portTwo)+' and dst_ip = cast('+str(hex(ipOne))+' as binary(4)) and dst_port = '+str(PortOne)+')'+' Limit ' + str(10*(int(page) - 1)) + ', 10'

    tcp_pack = db.engine.execute(searchTcpSQL)
    udp_pack = db.engine.execute(searchUdpSQL)

    for foundTcp in tcp_pack:
        # tcp_header hex
        tcp_headerInt = ''
        for ToHex in foundTcp.tcp_header:
            tcp_headerInt = tcp_headerInt + hex(ord(ToHex)) + ' '
        tcp_headerInt = tcp_headerInt[:-1]

        # ip_header hex
        ip_headerInt = ''
        for ToHex in foundTcp.ip_header:
            ip_headerInt = ip_headerInt + hex(ord(ToHex)) + ' '
        ip_headerInt = ip_headerInt[:-1]

        # src_ip str
        src_ipInt = ''
        for ToHex in foundTcp.src_ip:
            src_ipInt = src_ipInt + str(ord(ToHex)) + '.'
        src_ipInt = src_ipInt[:-1]

        # dst_ip str
        dst_ipInt = ''
        for ToHex in foundTcp.dst_ip:
            dst_ipInt = dst_ipInt + str(ord(ToHex)) + '.'
        dst_ipInt = dst_ipInt[:-1]

        # payload_data hex
        hex_str = ''
        for ToHex in foundTcp.payload_data:
            hex_str = hex_str + hex(ord(ToHex)) + ' '
        hex_str = hex_str[:-1]

        # payload_data ascii
        asc_str = ''
        asc_str = binToAsc(foundTcp.payload_data)

        TcpList.append([foundTcp, src_ipInt, dst_ipInt, hex_str, asc_str, ip_headerInt, tcp_headerInt])

    for foundUdp in udp_pack:
        # ip_header hex
        ip_headerInt = ''
        for ToHex in foundUdp.ip_header:
            ip_headerInt = ip_headerInt + hex(ord(ToHex)) + ' '
        ip_headerInt = ip_headerInt[:-1]

        # src_ip str
        src_ipInt = ''
        for ToHex in foundUdp.src_ip:
            src_ipInt = src_ipInt + str(ord(ToHex)) + '.'
        src_ipInt = src_ipInt[:-1]

        # dst_ip str
        dst_ipInt = ''
        for ToHex in foundUdp.dst_ip:
            dst_ipInt = src_ipInt + str(ord(ToHex)) + '.'
        dst_ipInt = dst_ipInt[:-1]

        # payload_data hex
        hex_str = ''
        for ToHex in foundUdp.payload_data:

            hex_str = hex_str + hex(ord(ToHex)) + ' '
        hex_str = hex_str[:-1]

        # payload_data ascii
        asc_str = ''
        asc_str = binToAsc(foundUdp.payload_data)

        UdpList.append([foundUdp, src_ipInt, dst_ipInt, hex_str, asc_str, ip_headerInt])

    return render_template('deepSearch.html', title='deepSearch', TcpList=TcpList, UdpList=UdpList, BackPage=BackPage, FrontPage=FrontPage, dst_ip=rawIpTwo, dst_port=portTwo, src_ip=rawIpOne, src_port=PortOne, packet_id=pack_id, page=page)
Beispiel #4
0
 def validate_rawIpTwo(self, rawIpTwo):
     if IpParser(rawIpTwo.data) is -1:
         raise ValidationError('Wrong input')
Beispiel #5
0
 def validate_src_ip(self, src_ip):
     if IpParser(src_ip.data) is -1:
         raise ValidationError('Wrong input')
Beispiel #6
0
 def validate_dst_ip(self, dst_ip):
     if IpParser(dst_ip.data) is -1:
         raise ValidationError('Wrong input')