Skip to content

Instantly share code, notes, and snippets.

@kjseefried
kjseefried / gist:8d0251b3b07e24d782e6
Last active August 29, 2015 14:06 — forked from anonymous/gist:5f97d8db71776b188820
better yet, just include a handful of function pointers into chan_t for each of the API methods that need more than the shared part of chan_t struct, initialize them on allocation and put type-specific code in these functions. It will make for a more compact, concise and localized code. (Edit 2) Here's what I mean with function pointers - https:…
typedef struct chan_t
{
pthread_mutex_t m_mu;
pthread_cond_t m_cond;
int closed;
void (* dispose)(struct chan_t * self);
...
} chan_t;
@kjseefried
kjseefried / hearbleed
Last active August 29, 2015 14:04
Find heartbleed with nmap
nmap --script-updatedb
get https://svn.nmap.org/nmap/nselib/tls.lua and put it in /usr/share/nmap/nselib/
get http://nmap.org/svn/scripts/ssl-heartbleed.nse and put it in /usr/share/nmap/scripts
nmap -d --script ssl-heartbleed --script-trace --script-args vulns.showall -sV 10.1.0.0/16
@kjseefried
kjseefried / smb-os-discovery.py
Created July 17, 2014 15:45
Example of python rig to use nmap module
import nmap
nm=nmap.PortScanner()
nm.scan('10.1.0.0/16', '445', arguments='--script=/usr/local/share/nmap/scripts/smb-os-discovery.nse')
@kjseefried
kjseefried / socket_sniff.py
Created July 15, 2014 01:19
Example of using the Python socket lib to sniff packets.
import socket
from struct import *
s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_TCP)
#'!BBBHHHHHHBBBBH5s5s'
while True:
packet= s.recvfrom(65565)
print packet
packet =packet[0]
print "\n",packet
@kjseefried
kjseefried / scapy_gobject.py
Created July 15, 2014 01:15
Example of using scapy+gobject to sniff packets.
import gobject
from scapy.all import *
loop = gobject.MainLoop()
ethernet1 = conf.L2listen(type=ETH_P_ALL, iface='eth0')
def ethernet1_handler(packet):
return packet.summary()
@kjseefried
kjseefried / scapy_icmp_unreachable.py
Created July 15, 2014 01:13
Return an ICMP unreachable to a packet. Scapy example.
# Sending ICMP HOST UNREACHABLE USING SCAPY (PYTHON TOOLS)
# Will WORK for UDP/TCP, just give the "packet" (scapy's representation)
def send_icmp_unreachable (packet):
global MYMAC
global IPGATEWAY
global INTERFACE
p = Ether(src=MYMAC, dst=packet.src)/IP(src=IPGATEWAY, dst=packet.getlayer(IP).src)
# ICMP type=3 code=1 Host Unreachable
@kjseefried
kjseefried / bitstring.py
Created July 15, 2014 01:09
Example of using Python bitstring
from bitstring import ConstBitArray, BitStream
# Opening from a file means that it won't be all read into memory
s = ConstBitArray(filename='test.ts')
outfile = open('test_nonull.ts', 'wb')
# Cut the stream into 188 byte packets
for packet in s.cut(188*8):
# Take a 13 bit slice and interpret as an unsigned integer
PID = packet[11:24].uint
@kjseefried
kjseefried / logs_to_process.adb
Created July 15, 2014 01:05
Example of using GNAT.regex
with GNAT.Regexp;
with Ada.Text_IO;
procedure logs_to_process is
Filename : String := "logs_to_process.txt";
File : Ada.Text_IO.File_Type;
Line_Count : Natural := 0;
ECD_Pattern : String := "*FILENAME*.ECD*";
ETD_Pattern : String := "*FILENAME*.ETD*";
@kjseefried
kjseefried / ada_vect2C.adb
Created July 15, 2014 00:41
Example to convert an ada vector to a c vector
type Index is range 1 .. 3;
type Ada_Vector is array (Index) of Float;
type C_Vector is array (Index) of C_Float;
function To_C (Item : in Ada_Vector) return C_Vector is
begin
return Result : C_Vector do
for I in Index loop
Result (I) := C_Float (Item (I));
end loop;
@kjseefried
kjseefried / fileinfo.adb
Created July 15, 2014 00:35
Example file utility in Ada from PB
with Ada.Text_IO; with ADA.IO_EXCEPTIONS;
with Ada.Command_Line;
with Ada.Directories;
with Ada.Strings.Bounded;
procedure FileInfo is
-- rename used packages
package IO renames Ada.Text_IO;
package FS renames Ada.Directories;
package Cmd renames Ada.Command_Line;