Skip to content

Instantly share code, notes, and snippets.

View viz-prakash's full-sized avatar

Vijay Prakash viz-prakash

  • USA
View GitHub Profile
@viz-prakash
viz-prakash / apache_forward_proxy.md
Last active January 4, 2024 21:17
Setup Apache HTTP forward proxy on Linux

With Apache server (difficult way and only works with HTTPS traffic)

On server proxy machine

Enable the proxy module

sudo a2enmod proxy

sudo a2enmod proxy_http

Uncomment following lines in /etc/apache2/mods-available/proxy.conf

@viz-prakash
viz-prakash / tree_plots.ipynb
Last active February 23, 2023 20:53
Tree (Graph) plots with networkx and pydot
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@viz-prakash
viz-prakash / connect_to_wifi.sh
Last active December 5, 2022 02:58
Connects to a wifi ssid available from command prompt on Raspberry pi
#!/bin/bash
# Connects to a wifi ssid available from command prompt on Raspberry pi
# run it with sudo
# you might have to kill wpa_supplicant and dhclient
# sudo killall wpa_supplicant
# sudo killall dhclient
apt -y install wireless-tools wpasupplicant
@viz-prakash
viz-prakash / dump_traffic.sh
Last active December 5, 2022 02:55
Copy TCPDUMP capture to remote location
#!/bin/bash
sudo pkill -9 -f tcpdump
while [ 1 ]
do
ip=`hostname -I | cut -f 1 -d ' '`
#exits after every 2 hrs
sudo tcpdump -i eth0 -G 7200 "host not $ip and not arp" -w - | ssh remote_location 'cat > ~/your_pcap_dir/`date +%F-%s`.pcap'
sleep 1
done
#!/usr/bin/env python3
import concurrent.futures
import subprocess
from time import sleep
from scapy.all import *
IP_A = "10.9.0.5"
MAC_A = "02:42:0a:09:00:05"
IP_B = "10.9.0.6"
MAC_B = "02:42:0a:09:00:06"
@viz-prakash
viz-prakash / matplotlib_extra_legend.ipynb
Last active February 23, 2023 20:50
Adding an extra legend in matplotlib
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@viz-prakash
viz-prakash / fixed_port_http.py
Created February 25, 2022 16:49
Python script to make HTTP connection from fixed port
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.poolmanager import PoolManager
import requests
class SourcePortAdapter(HTTPAdapter):
""""Transport adapter" that allows us to set the source port."""
def __init__(self, port, *args, **kwargs):
self._source_port = port
super(SourcePortAdapter, self).__init__(*args, **kwargs)
@viz-prakash
viz-prakash / pcap analysis filters.md
Last active July 5, 2022 21:44
Wireshark, tshark, and tcpdump filters

Useful filters for analyzing pcaps.

Wireshark

Wireshark has very nice and descriptive guide with examples on their official documentation page.

To select a TCP/UDP stream in a pcap, use tcp.stream filter, for e.g., tcp.stream eq 1 or udp.stream eq 0. If you are analysing a packet in a pcap and want to see the entire TCP/UDP session contaning that packet, you can do this as following: right click on the packet -> select Follow -> select TCP Stream or UDP Stream. You can also do the same thing by shorcut option + shift + cmd + U for UDP and option + shift + cmd + T for TCP on mac.

To see various statistics of different protocols use -z option on Wireshark/tshark command, for e.g., Wireshark -z conv,eth your.pcap. Same can be done by going to the menubar and selecting Statistics -> Coversations from the Wireshark GUI. For more options related to this see tshark [man page](https://www.wireshark

@viz-prakash
viz-prakash / scapy_packet_filter.py
Created January 27, 2020 02:55
Python script for Pcap parsing using Scapy, along with performance testing
#!/usr/bin/env python3
# -*- coding: ISO-8859-15 -*-
"""
This file contains some example methods of how pcaps can be parsed, filtered in different ways, and
converted to JSON representation with scapy and tshark(tshark is directly invoked on pcap).
It shows an example of how a tcp session can be extracted from a huge pcap consisting of multiple
sessions.
It also does a performance testing of those methods, but don't take the output as it is.