How to use the pypacker.pypacker function in pypacker

To help you get started, we’ve selected a few pypacker examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mike01 / pypacker / pypacker / layer12 / ieee80211.py View on Github external
def reverse_address(self):
			self.dst, self.src = self.src, self.dst

	class ReassocReq(pypacker.Packet):
		__hdr__ = (
			("dst", "6s", b"\x00" * 6),
			("src", "6s", b"\x00" * 6),
			("bssid", "6s", b"\x00" * 6),
			("seq_frag", "H", 0),
			("capa", "H", 0),
			("interval", "H", 0),
			("current_ap", "6s", b"\x00" * 6)
		)

		dst_s = pypacker.get_property_mac("dst")
		bssid_s = pypacker.get_property_mac("bssid")
		src_s = pypacker.get_property_mac("src")

		def _get_seq(self):
			return (self.seq_frag & 0xFF) << 4 | (self.seq_frag >> 12)

		def _set_seq(self, val):
			self.seq_frag = (val & 0xF) << 12 | (val & 0xFF0) >> 4 | (self.seq_frag & 0x0F00)

		seq = property(_get_seq, _set_seq)

		def reverse_address(self):
			self.dst, self.src = self.src, self.dst

	class Auth(pypacker.Packet):
		"""Authentication request."""
		__hdr__ = (
github mike01 / pypacker / pypacker / layerX / qq.py View on Github external
0x0023: "_CMD_TRANSFER",
	0x0026: "_CMD_REQUEST_BEGIN",
}


class QQBasicPacket(pypacker.Packet):
	__hdr__ = (
		("header_type", "B", 2),
		("source",	"H", 0),
		("command",	"H", 0),
		("sequence",	"H", 0),
		("qqNum",	"L", 0),
	)


class QQ3Packet(pypacker.Packet):
	 __hdr__ = (
		("header_type", "B", 3),
		("command",	"B", 0),
		("sequence",	"H", 0),
		("unknown1",	"L", 0),
		("unknown2",	"L", 0),
		("unknown3",	"L", 0),
		("unknown4",	"L", 0),
		("unknown5",	"L", 0),
		("unknown6",	"L", 0),
		("unknown7",	"L", 0),
		("unknown8",	"L", 0),
		("unknown9",	"L", 0),
		("unknown10",	"B", 1),
		("unknown11",	"B", 0),
		("unknown12",	"B", 0),
github mike01 / pypacker / pypacker / layer567 / rpc.py View on Github external
def unpack_xdrlist(cls, buf):
	l = []
	while buf:
		if buf.startswith("\x00\x00\x00\x01"):
			p = cls(buf[4:])
			l.append(p)
			buf = p.data
		elif buf.startswith("\x00\x00\x00\x00"):
			break
		else:
			raise pypacker.UnpackError("invalid XDR list")
	return l
github mike01 / pypacker / pypacker / layer3 / ip.py View on Github external
if length_payload - off > fragment_len:
				# more fragments follow
				ip_frag.flags = 0x1
			else:
				# last fragment
				ip_frag.flags = 0x0

			ip_frag.offset = int(off / 8)
			ip_frag.body_bytes = payload_sub
			fragments.append(ip_frag)
			off += fragment_len

		return fragments

	# Convenient access for: src[_s], dst[_s]
	src_s = pypacker.get_property_ip4("src")
	dst_s = pypacker.get_property_ip4("dst")

	def _dissect(self, buf):
		total_header_length = ((buf[0] & 0xf) << 2)
		options_length = total_header_length - 20		# total IHL - standard IP-len = options length

		if options_length > 0:
			# logger.debug("got some IP options: %s" % tl_opts)
			self._init_triggerlist("opts", buf[20: 20 + options_length], self._parse_opts)
		elif options_length < 0:
			# invalid header length: assume no options at all
			raise Exception()
		# TODO: extract real data length:
		# There are some cases where padding can not be identified on ethernet -> do it here (eg VSS shit trailer)
		self._init_handler(buf[9], buf[total_header_length:])
		return total_header_length
github mike01 / pypacker / tools / ap_dos.py View on Github external
aps_per_channel = 5
	current_channel = 1

	for i in range(1, 10000):
		if i % 100 == 0:
			diff = time.time() - start_time
			print("%d pps" % (i / diff))
		if i % aps_per_channel == 0:
			current_channel += 1
			current_channel %= 13
			if current_channel == 0:
				current_channel = 1
			# utils.switch_wlan_channel(wlan_monitor_if, current_channel)

		_beacon = beacon[ieee80211.IEEE80211.Beacon]
		mac = pypacker.get_rnd_mac()
		_beacon.src = mac
		_beacon.bssid = mac
		# set new ssid
		_beacon.params[0].body_bytes = bytes("".join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10)), "ascii")
		# print(_beacon.params[0].body_bytes)
		_beacon.seq = 0

		# print(_beacon)

		try:
			for x in range(100):
				# send multiple beacons for every ap
				psocket.send(beacon.bin())
				_beacon.seq = x
				# _beacon.ts = x << (8*7)
				_beacon.ts = x
github mike01 / pypacker / pypacker / layer12 / pppoe.py View on Github external
"""PPP-over-Ethernet."""
from pypacker import pypacker
from pypacker.layer12.ppp import PPP

# RFC 2516 codes
PPPoE_PADI	= 0x09
PPPoE_PADO	= 0x07
PPPoE_PADR	= 0x19
PPPoE_PADS	= 0x65
PPPoE_PADT	= 0xA7
PPPoE_SESSION	= 0x00


class PPPoE(pypacker.Packet):
	__hdr__ = (
		("v_type", "B", 0x11),
		("code", "B", 0),
		("session", "H", 0),
		("len", "H", 0)  # payload length
	)

	def __get_v(self):
		return self.v_type >> 4

	def __set_v(self, v):
		self.v_type = (v << 4) | (self.v_type & 0xf)
	v = property(__get_v, __set_v)

	def __get_type(self):
		return self.v_type & 0xf
github mike01 / pypacker / pypacker / layer12 / arp.py View on Github external
class ARP(pypacker.Packet):
	__hdr__ = (
		("hrd", "H", ARP_HRD_ETH),
		("pro", "H", ARP_PRO_IP),
		("hln", "B", 6),			# hardware address length
		("pln", "B", 4),			# protocol address length
		("op", "H", ARP_OP_REQUEST),
		("sha", "6s", b"\x00" * 6),		# sender mac
		("spa", "4s", b"\x00" * 4),		# sender ip
		("tha", "6s", b"\x00" * 6),		# target mac
		("tpa", "4s", b"\x00" * 4)		# target ip
	)

	# convenient access
	sha_s = pypacker.get_property_mac("sha")
	spa_s = pypacker.get_property_ip4("spa")
	tha_s = pypacker.get_property_mac("tha")
	tpa_s = pypacker.get_property_ip4("tpa")
github mike01 / pypacker / pypacker / utils.py View on Github external
"""
Utility functions.
"""
import subprocess
import re
import os
import logging
import math

from pypacker import pypacker as pypacker

log = math.log
mac_bytes_to_str = pypacker.mac_bytes_to_str

logger = logging.getLogger("pypacker")


def switch_wlan_channel(iface, channel, shutdown_prior=False):
	"""
	Switch wlan channel to channel.
	Requirements: ifconfig, iwconfig

	iface -- interface name
	channel -- channel numer to be set as number
	shutdown_prior -- shut down interface prior to setting channel
	"""
	if shutdown_prior:
		cmd_call = ["ifconfig", iface, "down"]
		subprocess.check_call(cmd_call)
github mike01 / pypacker / pypacker / layer4 / sccp.py View on Github external
("echo_cancel_type", "I", 4),
		("g723_bitrate", "I", 0),
	)


class OpenReceiveChannelAck(pypacker.Packet):
	__byte_order__ = "<"
	__hdr__ = (
		("channel_status", "I", 0),
		("ip", "4s", ""),
		("port", "I", 0),
		("passthruparty_id", "I", 0),
	)


class SelectStartKeys(pypacker.Packet):
	__byte_order__ = "<"
	__hdr__ = (
		("line_id", "I", 1),
		("call_id", "I", 0),
		("softkey_set", "I", 8),
		("softkey_map", "I", 0xffffffff)
	)


class SetLamp(pypacker.Packet):
	__byte_order__ = "<"
	__hdr__ = (
		("stimulus", "I", 9),		# 9: Line
		("stimulus_instance", "I", 1),
		("lamp_mode", "I", 1),
	)
github mike01 / pypacker / pypacker / layer3 / pim.py View on Github external
"""Protocol Independent Multicast."""

from pypacker import pypacker, checksum
from pypacker.pypacker import FIELD_FLAG_AUTOUPDATE


class PIM(pypacker.Packet):
	__hdr__ = (
		("v_type", "B", 0x20),
		("rsvd", "B", 0),
		("sum", "H", 0, FIELD_FLAG_AUTOUPDATE)  # _sum = sum
	)

	def __get_v(self):
		return self.v_type >> 4

	def __set_v(self, v):
		self.v_type = (v << 4) | (self.v_type & 0xf)
	v = property(__get_v, __set_v)

	def __get_type(self):
		return self.v_type & 0xf