News:

How did you even find this place?

Main Menu

[Python] Packetbuffer

Started by igimo1, May 23, 2006, 08:13:28 PM

Previous topic - Next topic

0 Members and 5 Guests are viewing this topic.

igimo1

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.

GameSnake

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.

Sidoh

Quote from: GameSnake 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.

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

Joe

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?
Quote from: Camel on June 09, 2009, 04:12:23 PMI'd personally do as Joe suggests

Quote from: AntiVirus on October 19, 2010, 02:36:52 PM
You might be right about that, Joe.


GameSnake

#4
Quote from: Joe 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?
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 on May 24, 2006, 11:03:03 PM
Quote from: GameSnake 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.

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

Sidoh

Quote from: GameSnake on May 24, 2006, 11:24:59 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

Sidoh

Quote from: PancakeAssassin on May 24, 2006, 11:54:40 PM
This is cool,

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

Quote from: GameSnake on May 24, 2006, 11:24:59 PM
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.

Joe

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.
Quote from: Camel on June 09, 2009, 04:12:23 PMI'd personally do as Joe suggests

Quote from: AntiVirus on October 19, 2010, 02:36:52 PM
You might be right about that, Joe.


GameSnake

Quote from: Joe 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.
python.org

Joe

Quote from: Camel on June 09, 2009, 04:12:23 PMI'd personally do as Joe suggests

Quote from: AntiVirus on October 19, 2010, 02:36:52 PM
You might be right about that, Joe.


GameSnake


Joe

Quote from: Camel on June 09, 2009, 04:12:23 PMI'd personally do as Joe suggests

Quote from: AntiVirus on October 19, 2010, 02:36:52 PM
You might be right about that, Joe.


igimo1

#12
This code sucks, much more elegant if the code is geared towards a purpose, ie parsing incoming data;

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

Quote from: Joex86/64] link=topic=5956.msg70892#msg70892 date=1148527106]
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.

warz

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

igimo1