Skip to content

Instantly share code, notes, and snippets.

@antoni
antoni / JsonServer.py
Created April 26, 2017 10:38
JSON server, which serves local directory static files according to file's basename.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
JSON server, which serves local directory static files according to file's basename.
echo '{"key": "valuy"}' > resp.json
python -m JsonServer
curl http://localhost:8000/resp
"""
@antoni
antoni / install_google_cloud_sdk.sh
Created April 13, 2017 11:23
A script for installing Google Cloud SDK on Ubuntu.Debian
#!/usr/bin/bash
# Create an environment variable for the correct distribution
export CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)"
# Add the Cloud SDK distribution URI as a package source
echo "deb https://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
# Import the Google Cloud Platform public key
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
@antoni
antoni / ns-inet.sh
Created August 27, 2016 18:11 — forked from dpino/ns-inet.sh
Setup a network namespace with Internet access
#!/usr/bin/env bash
set -x
NS="ns1"
VETH="veth1"
VPEER="vpeer1"
VETH_ADDR="10.200.1.1"
VPEER_ADDR="10.200.1.2"
@antoni
antoni / Makefile
Created August 26, 2016 15:14
A Super-Simple Makefile for Medium-Sized C/C++ Projects (https://spin.atomicobject.com/2016/08/26/makefile-c-projects/)
TARGET_EXEC ?= a.out
BUILD_DIR ?= ./build
SRC_DIRS ?= ./src
SRCS := $(shell find $(SRC_DIRS) -name *.cpp -or -name *.c -or -name *.s)
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)
INC_DIRS := $(shell find $(SRC_DIRS) -type d)
def _parse_boot_device_list(boot_device_list):
"""
Returns boot devices order specified by current_assigned_sequence field
(a list with names of the devices)
"""
boot_order = []
for _, devices in boot_device_list.items():
for boot_device in devices:
id_parts = boot_device.id.split("#")
@antoni
antoni / Local MITM SSH proxy
Created July 27, 2016 12:13
Local MITM SSH proxy
sudo iptables -t nat -D OUTPUT -p tcp -m owner ! --uid-owner root --dport 443 -j REDIRECT --to-port 8080
This document describes about installation and configuration of IPMI simulator.
We need: qemu-kvm, OpenIPMI, OpenIPMI-tools
1) Install the qemu-kvm. We need the qemu, which have the IPMI pacthes.
Use the source https://github.com/cminyard/qemu/tree/stable-2.2-ipmi
./configure, make and make install
2) Download the OpenIPMI libraries, from http://sourceforge.net/projects/openipmi/
Follow the process documented in lanserv/README.vm
./configure --prefix=/opt/openipmi/usr --sysconfdir=/opt/openipmi/etc \
--with-perlinstall=/opt/openipmi/usr/lib/perl \
@antoni
antoni / mysql_secure.sh
Created May 14, 2016 22:07 — forked from Mins/mysql_secure.sh
Automating mysql_secure_installation
#!/bin/bash
aptitude -y install expect
// Not required in actual script
MYSQL_ROOT_PASSWORD=abcd1234
SECURE_MYSQL=$(expect -c "
set timeout 10
@antoni
antoni / gist:83edb611014b8255a2708f0d3ec5a21a
Last active April 25, 2016 09:09
Terminal escape sequences
# Source: https://m.reddit.com/r/netsec/comments/4fi3hn/detecting_the_use_of_curl_bash_server_side/
$ cat > evil.sh <<EOF
echo rm -rf /home; FOO=^M echo "nothing fishy here!"
EOF
$ cat evil.sh
echo "nothing fishy here!"
$ source evil.sh
rm -rf /home
nothing fishy here!
@antoni
antoni / FileDownload.java
Created April 13, 2016 13:51
Download file using Java NIO
URL website = new URL(FILE_URL);
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(TMP_FILE_NAME);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);