Author Topic: [Python] Packetbuffer  (Read 15931 times)

0 Members and 3 Guests are viewing this topic.

Offline igimo1

  • Full Member
  • ***
  • Posts: 420
    • View Profile
[Python] Packetbuffer
« on: May 23, 2006, 08:13:28 pm »
Quote
#packet buffer

__author__ = 'topaz'
__copyright = 'BSD License'

import string
import struct
import main

class pBuffer:

    def __init__(self):
        self.buffer = list()
        #declares self.buffer as a list
   
    def insertData(self, data):
        self.buffer.append(data)

    def insertInteger(self, data):
        if string.isdigit(data) == false:
            return
        else:
            data = struct.pack('I', data)
                #converts data into unsigned int and adds it into the buffer
                #converting integers into dwords/words is unnecessary, so we
                #simply pack it and append it
            self.buffer.append(data)

    def insertIntegerList(self, data):
        if string.isdigit(data) == false:
            return
        else:
            self.buffer.append('%s' %data)
            #adds a list of integers into the buffer

    def insertString(self, data):
        self.buffer.append(data)

    def insertNTString(self, data):
        self.buffer.append('%s.' % data)
        #adds string into buffer with a null terminator

    def makeInteger(self, data):
        data = struct.pack('I', data)

        return data
   
    def strToHex(self, data):
        data = data.encode('hex')

        return data
       
    def makeLong(self, data):
        data = struct.pack('L', data)
        #convert data into a Long and return it

        return data
   
    def hexToStr(self, data):
        data = data.decode('hex')
        #decodes data back into string and returns it

        return data

    def GetDWORD(self, data):
        #transform data into an integer and return it
        data = int(data)

        return data
       
    def GetWORD(self, data):
        data = int(data)

        return data

    def insertBYTE(self, data):
        data = Chr(data)
        #convert data into byte format and return it

        self.buffer.append(data)
   
    def sendPacket(self, packetID):
        main.transport.write(self.buffer)

        clear()

    def clear(self):
        #clears the buffer
        self.buffer[:] = []

Updated code.
« Last Edit: May 24, 2006, 12:08:40 pm by Topaz »

Offline GameSnake

  • News hound
  • Hero Member
  • *****
  • Posts: 2937
    • View Profile
Re: [Python] Packetbuffer
« Reply #1 on: May 24, 2006, 10:54:24 pm »
I'm a Python developer. I tried this code out in the Python IDLE GUI along with a homemade structure code and it works suprisingly well.

Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: [Python] Packetbuffer
« Reply #2 on: May 24, 2006, 11:03:03 pm »
I'm a Python developer. I tried this code out in the Python IDLE GUI along with a homemade structure code and it works suprisingly well.

It's . . . 200 lines, tops?  Unless you lack simple analsys skills, I don't see how it would be that surprising.

What did you mean by "surprising," anyway?  Are you being condescending? :P

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: [Python] Packetbuffer
« Reply #3 on: May 24, 2006, 11:18:26 pm »
I'd be interested in seeing a bot written in Python. I've never used the language - does it have a nice API including networking stuff as well, or is it more like Brainfuck where you have nothing at all?
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline GameSnake

  • News hound
  • Hero Member
  • *****
  • Posts: 2937
    • View Profile
Re: [Python] Packetbuffer
« Reply #4 on: May 24, 2006, 11:24:59 pm »
I'd be interested in seeing a bot written in Python. I've never used the language - does it have a nice API including networking stuff as well?
Yes. Although a little outdated, Python is a simple yet powerfull language. If your interested, $t0rm has made a bot using Python before, the only problem is the GUI, you need another program that can interface python with a GUI.
I'm a Python developer. I tried this code out in the Python IDLE GUI along with a homemade structure code and it works suprisingly well.

It's . . . 200 lines, tops?  Unless you lack simple analsys skills, I don't see how it would be that surprising.

What did you mean by "surprising," anyway?  Are you being condescending? :P
Condecsending, you never know with Topaz, I was just confirming to everyone that the code does work ;). It is rare to find Python code in bot development
« Last Edit: May 24, 2006, 11:31:28 pm by GameSnake »

Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: [Python] Packetbuffer
« Reply #5 on: May 24, 2006, 11:44:30 pm »
Condecsending, you never know with Topaz, I was just confirming to everyone that the code does work ;). It is rare to find Python code in bot development

Your response either convoluted or nonsensical. :P

Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: [Python] Packetbuffer
« Reply #6 on: May 25, 2006, 12:05:43 am »
This is cool,

anyone ever done a bot in python or something like that? i'd be interested in learning it

Yes. Although a little outdated, Python is a simple yet powerfull language. If your interested, $t0rm has made a bot using Python before, the only problem is the GUI, you need another program that can interface python with a GUI.
Quote from: Sidoh link=topic=5956.msg70889#msg70889
[/quote

I'm pretty sure I know the storm he's talking about.  Is this the same one that uses coldfusion a lot and hates PHP?  I work for a guy he used to work for.

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: [Python] Packetbuffer
« Reply #7 on: May 25, 2006, 11:49:05 pm »
You have some fubared quote tags, Sidoh.

Linkage, GameSnake? I don't plan on using it, of course, but I thought I'd be interesting.
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline GameSnake

  • News hound
  • Hero Member
  • *****
  • Posts: 2937
    • View Profile
Re: [Python] Packetbuffer
« Reply #8 on: May 26, 2006, 02:20:50 pm »
You have some fubared quote tags, Sidoh.

Linkage, GameSnake? I don't plan on using it, of course, but I thought I'd be interesting.
python.org

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: [Python] Packetbuffer
« Reply #9 on: May 27, 2006, 01:17:01 pm »
I meant his bot. =p
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline GameSnake

  • News hound
  • Hero Member
  • *****
  • Posts: 2937
    • View Profile
Re: [Python] Packetbuffer
« Reply #10 on: May 28, 2006, 12:32:03 am »
I meant his bot. =p
Ask him for it.

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: [Python] Packetbuffer
« Reply #11 on: May 29, 2006, 02:13:47 am »
I don't know storm.
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline igimo1

  • Full Member
  • ***
  • Posts: 420
    • View Profile
Re: [Python] Packetbuffer
« Reply #12 on: July 12, 2007, 11:50:52 pm »
This code sucks, much more elegant if the code is geared towards a purpose, ie parsing incoming data;

Code: [Select]
import struct

def unpack_dword(data):
    return struct.unpack('I', data)[0]

def unpack_word(data):
    return struct.unpack('H', data)[0]

def unpack_byte(data):
    return struct.unpack('<B', data)[0]

class recv_buffer:
    def __init__(self, raw_buffer):
        self.raw_buffer = raw_buffer
        self.position = 0

    def jump(self, bytes):
        self.position += bytes

    def back(self, bytes):
        self.position -= bytes

    def set_position(self, position):
        self.position = position

    def next_string(self):
        pos = self.raw_buffer.find(chr(0), self.position)
        string = self.raw_buffer[self.position:pos]

        self.set_position(pos + 1)
        return string

    def next_byte(self):
        param = self.raw_buffer[self.position:self.position + 1]
        byte = unpack_byte(param)

        self.jump(1)
        return byte

    def next_dword(self):
        param = self.raw_buffer[self.position:self.position + 4]
        dword = unpack_dword(param)

        self.jump(4)
        return dword

    def next_word(self):
        param = self.raw_buffer[self.position:self.position + 2]
        word = unpack_word(param)

        self.jump(2)
        return word

    def next_dword_list(self, size):
        dword_list = []

        for i in xrange(size):
            dword_list.append(self.next_dword())

        return dword_list

    def next_data(self, bytes):
        return self.raw_buffer[self.position: self.position + bytes]

    def dump_data(self):
        self.raw_buffer = ""

Much shorter, too, unlike the code from a good year ago

I'd be interested in seeing a bot written in Python. I've never used the language - does it have a nice API including networking stuff as well, or is it more like Brainfuck where you have nothing at all?

Python is very easy to learn (I've seen users dub it "visual basic 2", or some other clever nick). The stdlib is huge, much like Java's. There is a significant amount of networking modules built-in.

The bot has been available for some time. I ran into some phantom bugs while I was working on it, but it has enough done that it should be easily completed. In fact, some leech even thought it complete enough to use and plaster his name on it without giving credit.
« Last Edit: July 13, 2007, 03:27:18 am by Topaz »

Offline warz

  • Hero Member
  • *****
  • Posts: 1134
    • View Profile
    • chyea.org
Re: [Python] Packetbuffer
« Reply #13 on: July 13, 2007, 02:59:36 am »
Python is not even comparable to Brainfuck - who asks that?

topaz, continue searching for slaughter.. maybe check our irc network again - wait, you can't roflmaomfommaomrfolol
http://www.chyea.org/ - web based markup debugger

Offline igimo1

  • Full Member
  • ***
  • Posts: 420
    • View Profile
Re: [Python] Packetbuffer
« Reply #14 on: July 13, 2007, 03:26:47 am »
Are you sure?