Skip to content

Instantly share code, notes, and snippets.

Avatar

Alfred Moreno kryptek

  • Amazon Web Services
  • Seattle, WA
View GitHub Profile
@kryptek
kryptek / ethtool.py
Created Nov 30, 2020 — forked from yunazuno/ethtool.py
ethtool -S in Python
View ethtool.py
#!/usr/bin/env python
import socket
import fcntl
import struct
import array
SIOCETHTOOL = 0x8946
ETHTOOL_GSTRINGS = 0x0000001b
ETHTOOL_GSSET_INFO = 0x00000037
ETHTOOL_GSTATS = 0x0000001d
@kryptek
kryptek / vpn-openconnect-connect-to-cisco-anyconnect.md Split tunneling with openconnect - A guide on how to use openconnect to establish a vpn connection to an enterprise cisco anyconnect vpn endpoint with client side routing.
View vpn-openconnect-connect-to-cisco-anyconnect.md

Introduction

The purpose of this short howto is to show you how to:

  • use openconnect [1] to connect to an enterprise cisco anyconnect endpoint
  • whilst minimizing the amount of traffic that your route through the vpn connection

Usually VPN administrators will puth the default route to the users, so that all user traffic is routed through the vpn connection. This is to address the various security concerns around compromised user computers bridging external internet traffic into the secure VPN network.

While the VPN administrator can push routes to the clients, the client can ignore these default routes and establish client side routing so that only the required A.B.C.D/E network is routed through the VPN. All other traffic will still use the clients default route and default outbound internet connection.

@kryptek
kryptek / transmission_remove_finished.sh
Created Mar 7, 2020 — forked from pawelszydlo/transmission_remove_finished.sh
Script to clear finished torrents from transmission-daemon
View transmission_remove_finished.sh
#!/bin/bash
# port, username, password
SERVER="localhost:9091 --auth user:pass"
# use transmission-remote to get torrent list from transmission-remote list
TORRENTLIST=`transmission-remote $SERVER --list | sed -e '1d' -e '$d' | awk '{print $1}' | sed -e 's/[^0-9]*//g'`
# for each torrent in the list
for TORRENTID in $TORRENTLIST
@kryptek
kryptek / ssh.py
Created Sep 25, 2018
Paramiko SSH
View ssh.py
import logging
import os
import paramiko
import subprocess
import socket
import time
logging.basicConfig(level=logging.INFO, datefmt='%F %T', format='%(asctime)s %(name)s.%(module)s %(levelname)s: %(message)s')
logger = logging.getLogger('ssh_client')
@kryptek
kryptek / ssh.py
Created Sep 25, 2018 — forked from jn0/ssh.py
Custom paramiko-based python SSH client class to asynchronously run time-limited non-interactive commands and return exit status along with stdout and stderr.
View ssh.py
#!/usr/bin/python
# -*- coding: UTF-8 -*-
'''
Custom SSH client.
1. It somehow _supports_ async execution.
2. It provides exit status.
3. It jams stdin (ssh -nT).
Run like something "python ssh.py box user=bs command='echo aaa; echo bbb >&2; sleep 40; exit 23'" to test
@kryptek
kryptek / Chapter1
Created Jul 10, 2018 — forked from sh1nu11bi/Chapter1
Black Hat Python_Personal Mod Code
View Chapter1
This code is taken fro Chapter 1-Mods included
View disable mcafee endpoint protection.md

method 1

sudo /usr/local/McAfee/AntiMalware/VSControl stopoas

alternatively

sudo defaults write /Library/Preferences/com.mcafee.ssm.antimalware.plist OAS_Enable -bool False
sudo /usr/local/McAfee/AntiMalware/VSControl stop
sudo /usr/local/McAfee/AntiMalware/VSControl reload
@kryptek
kryptek / bootstrap.sh
Created Oct 7, 2017 — forked from shostakovich/bootstrap.sh
Chef Solo on Mac OS X - examples
View bootstrap.sh
#!/bin/sh
USERNAME=shostakovich
mkdir ~/tmp
cd ~/tmp
# Install GCC + Git
curl https://github.com/downloads/kennethreitz/osx-gcc-installer/GCC-10.7-v2.pkg > GCC-10.7-v2.pkg
sudo installer -pkg GCC-10.7-v2.pkg -target /
@kryptek
kryptek / ssh-agent-forward.md
Created Aug 18, 2017 — forked from toejough/ssh-agent-forward.md
SSH Agent Forwarding in Python: Paramiko's undocumented API
View ssh-agent-forward.md

What

A how-to for ssh-agent forwarding via Paramiko. Specifically, I used Paramiko v1.15.2 in this example.

Why

Paramiko's docs do not document the API required to do ssh-agent forwarding. I ended up finding out how by reading pull requests for ssh-agent forwarding features in frameworks that use Paramiko under the covers, like fabric and ansible.

Update:

Besides attempting to document this process here, I've opened a bug with Paramiko to document this API in their official docs.

How

@kryptek
kryptek / dijkstra.py
Created Feb 11, 2017 — forked from kachayev/dijkstra.py
Dijkstra shortest path algorithm based on python heapq heap implementation
View dijkstra.py
from collections import defaultdict
from heapq import *
def dijkstra(edges, f, t):
g = defaultdict(list)
for l,r,c in edges:
g[l].append((c,r))
q, seen = [(0,f,())], set()
while q: