Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 34

Thread: Beginners programming challenge #28

  1. #11
    Join Date
    May 2008
    Location
    UK
    Beans
    1,450
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Beginners programming challenge #28

    I have an idea for a data driven protocol interpreter in python, but I wont post any code since strictly speaking I don't feel i am a beginner.
    Tony - Happy to try to help.
    Unless otherwise stated - all code posted by me is untested. Remember to Mark the Thread as Solved.
    Ubuntu user number # 24044 Projects : TimeWarp - on the fly Backups

  2. #12
    Join Date
    May 2011
    Beans
    253
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Beginners programming challenge #28

    Great challenge Bachstelze.

    I don't have any free time at the moment but am hoping that this will change in a few weeks. I think I'll do the programming challenges over winter. Hopefully I'll get to yours before school starts back up in January.
    Kevin Harper
    http://www.kevinharper.com/


    Ubuntu: Because rebooting is ONLY for installing hardware

  3. #13
    Join Date
    May 2006
    Location
    Boston
    Beans
    1,909
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Beginners programming challenge #28

    just asking why the old Programming Challenges are closed. some ppl weren't around at the time and the challenges are a good way to keep ppl motivated in trying .. or you expect a begginer to start from challenge 28?

    blog
    Donations BTC : 12FwoB7uAM5FnweykpR1AEEDVFaTLTYFkS
    DOUBLEPLUSGOOD!!

  4. #14
    Join Date
    Nov 2005
    Location
    Bordeaux, France
    Beans
    11,294
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Beginners programming challenge #28

    Quote Originally Posted by fdrake View Post
    just asking why the old Programming Challenges are closed. some ppl weren't around at the time and the challenges are a good way to keep ppl motivated in trying .. or you expect a begginer to start from challenge 28?
    The old challenges are closed in the sense that a winner has already been chosen. However, the threads are not closed, you are welcome to try them and post your solution in the corresponding thread if you want comments.
    Last edited by Bachstelze; December 23rd, 2012 at 03:01 PM.
    「明後日の夕方には帰ってるからね。」


  5. #15
    Join Date
    May 2006
    Location
    Boston
    Beans
    1,909
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Beginners programming challenge #28

    Quote Originally Posted by Bachstelze View Post
    The old challenges are closed in the sense that a winner has already been chosen. However, the threads are not closed, you are welcome to try them and post your solution in the corresponding thread if you want scomments.
    gotcha ya!

    blog
    Donations BTC : 12FwoB7uAM5FnweykpR1AEEDVFaTLTYFkS
    DOUBLEPLUSGOOD!!

  6. #16
    Join Date
    May 2006
    Location
    Boston
    Beans
    1,909
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Beginners programming challenge #28

    Quote Originally Posted by fdrake View Post
    gotcha ya!
    actually some threads are closed since I cannot post on them. like #1 . that's fine I'll look for the open ones.

    blog
    Donations BTC : 12FwoB7uAM5FnweykpR1AEEDVFaTLTYFkS
    DOUBLEPLUSGOOD!!

  7. #17
    Join Date
    Nov 2005
    Location
    Bordeaux, France
    Beans
    11,294
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Beginners programming challenge #28

    Oh yes, #1 is closed. You can use the report button to ask for a reopen, or post here.
    「明後日の夕方には帰ってるからね。」


  8. #18
    Join Date
    Sep 2011
    Beans
    10

    Re: Beginners programming challenge #28

    Thanks for putting together this challenge, I'm learning a lot! I'm afraid I'm in way over my head though, and was hoping somebody could point me in the right direction.

    I feel like I have a decent handle now on the structure of the packets - I've looked at them both in wireshark and the hexdump in a text editor. I have a plan for how to process and display the information once I get it into my program (this part of the program is not written yet).

    Where I'm running into trouble is actually getting the contents of the raw .bin files into my program. I'm not even sure what information they have in them, so I'm not certain how to proceed. I do notice that I can use "readlines()" to get a string of the hex octets, but "read()" and "readline()" both give unprintable characters. I haven't been able to make sense of why this is, although I imagine it has something to do with the information that lays out the numbering of the packet structure (on the far left of the hexdump file in gedit/wireshark)?

    This is the hex string I'm getting:
    Code:
    ['\xff\xff\xff\xff\xff\xff\xca\x013e\x00\x08\x08\x06\x00\x01\x08\x00\x06\x04\x00\x01\xca\x013e\x00\x08\xc0\xa8\x01\x01\x00\x00\x00\x00\x00\x00\xc0\xa8\x01\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00']
    I realize this corresponds to the octets in the packet, although I'm not certain why I'm getting "x013e" which appears to correspond to "01 33 65".

    Also, even getting the hex string, I can't seem to process it in any way. I'm trying to take the hex and display it in decimal, but keep getting errors. I've commented out my two latest attempts, one of which includes the struct method. I've read the docs for that over and over, and am starting to grasp a bit of it, but it's way over my head. Am I even heading down the right path with struct?

    I've attached my program so far, it's far from complete, I'm just trying to print the contents of the packet file right now. I'm very new to Python, so I appreciate any other pointers on my code as well. I know I have a lot of questions, but if someone could just point me in the right direction, I'm not afraid of doing some more searching/reading. Thanks!

    PHP Code:
    #!/usr/bin/python
    from __future__ import print_function
    from struct import 
    *
    import sys

    def getFile
    ():
        
    #I bet there's a cleaner way to do this? Pass file path after "-f "
        
    file sys.argv[(sys.argv.index("-f")) + 1]
        return(
    file)

    def getBits(file):
        
    open(file"r")
        
    data str(f.readlines())
        
    #Why does only readlines work here? What is the other "gibberish" in the file?
        
    f.close()
        
    #decData = unpack('30H', data)
        #decData = int(data, 0)
        
    return(decData)

    def main():
        
    file getFile()
        
    data getBits(file)
        print(
    data)

    main() 

  9. #19
    Join Date
    Nov 2010
    Beans
    271
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Beginners programming challenge #28

    @Bachstelze Very interesting challenge. I'll code it tonight and make a post tomorrow possibly. And, btw, winner of #27 hasn't been announced yet.. although there's only two entries (probably)

    ====

    I've got a question, Is the arp packet capsuled in the ethernet frame as a payload or is it a stand alone packet?
    Last edited by debd; January 7th, 2013 at 04:27 PM.

  10. #20
    Join Date
    Sep 2011
    Beans
    10

    Re: Beginners programming challenge #28

    Alright, it took long enough, but I think I've got it. It isn't the most elegant solution perhaps (especially formatting the MAC and IP addresses...) but it seems to work.

    I'd appreciate any feedback! I've learned a lot through this exercise, and I'm sure I can learn plenty more from critiques on how I did it.

    PHP Code:
    #!/usr/bin/python
    from __future__ import print_function
    import argparse
    import binascii


    def getBits
    (file):
        
    packet open(file"r")
        
    data binascii.hexlify(packet.read())    
        
    packet.close()
        return(
    data)

    def processPacket(data):
        
    #First 14 octets of ethernet frame are ethernet header
        #Realized that Preamble and Start of Frame Delimiter aren't seen on OSI Level 2
        
    ether0x data[0:28]

        
    macDest ether0x[0:12]
        
    macSrc ether0x[12:24]
        
    type ether0x[24:28]

        
    macDestination str(macDest[0:2]) + ':' str(macDest[2:4]) + ':' str(macDest[4:6]) + ':' str(macDest[6:8]) + ':' str(macDest[8:10]) + ':' +  str(macDest[10:12])
        
    macSource str(macSrc[0:2]) + ':' str(macSrc[2:4]) + ':' str(macSrc[4:6]) + ':' str(macSrc[6:8]) + ':' str(macSrc[8:10]) + ':' +  str(macSrc[10:12])

        print()
        print(
    "[+] Ethernet Header")
        print(
    " * Destination MAC Address: " str(macDestination))
        print(
    " * Source MAC Address: " str(macSource))
        print(
    " * EtherType: 0x" str(type))

        
    #Next is the ARP packet, 28 octets
        
    arp0x data[28:84]

        
    htype arp0x[0:4]
        
    ptype arp0x[4:8]
        
    hlen arp0x[8:10]
        
    plen arp0x[10:12]
        
    oper arp0x[12:16]
        
    sha arp0x[16:28]
        
    spa arp0x[28:36]
        
    tha arp0x[36:48]
        
    tpa arp0x[48:56]

        if 
    int(oper16) == 1:
            
    oper "REQUEST"
        
    elif int(oper16) == 2:
            
    oper "REPLY"

        
    senderProtocol str(int(spa[0:2], 16)) + '.' str(int(spa[2:4], 16)) + '.' str(int(spa[4:6], 16)) + '.' str(int(spa[6:8], 16))
        
    targetProtocol str(int(tpa[0:2], 16)) + '.' str(int(tpa[2:4], 16)) + '.' str(int(tpa[4:6], 16)) + '.' str(int(tpa[6:8], 16))

        
    senderHardware str(sha[0:2]) + ':' str(sha[2:4]) + ':' str(sha[4:6]) + ':' str(sha[6:8]) + ':' str(sha[8:10]) + ':' +  str(sha[10:12])
        
    targetHardware str(tha[0:2]) + ':' str(tha[2:4]) + ':' str(tha[4:6]) + ':' str(tha[6:8]) + ':' str(tha[8:10]) + ':' +  str(tha[10:12])
        
        print()
        print(
    "[+] ARP Packet")
        print(
    " * Hardware Type: " str(int((htype), 16)))
        print(
    " * Protocol Type: 0x" str(ptype))
        print(
    " * Hardware Length: " str(int((hlen), 16)))
        print(
    " * Protocol Length: " str(int((plen), 16)))
        print(
    " * Operation: " str(oper))
        print(
    " * Sender Hardware Address: " str(senderHardware))
        print(
    " * Sender Protocol Address: " str(senderProtocol))
        print(
    " * Target Hardware Address: " str(targetHardware))
        print(
    " * Target Protocol Address: " str(targetProtocol))

        return

    def main():
        
    parser argparse.ArgumentParser()
        
    parser.add_argument("file"help="Path to packet file")
        
    args parser.parse_args()

        
    file args.file
        data 
    getBits(file)
        
    processPacket(data)

    main() 

Page 2 of 4 FirstFirst 1234 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •