Skip to content

Instantly share code, notes, and snippets.

View master-hax's full-sized avatar
💤
sleeping

Vivek master-hax

💤
sleeping
View GitHub Profile
@mjohnsullivan
mjohnsullivan / http_server.rs
Last active March 12, 2024 16:08
Simple HTTP server example for Rust
// Updated example from http://rosettacode.org/wiki/Hello_world/Web_server#Rust
// to work with Rust 1.0 beta
use std::net::{TcpStream, TcpListener};
use std::io::{Read, Write};
use std::thread;
fn handle_read(mut stream: &TcpStream) {
let mut buf = [0u8 ;4096];
@PeteGoo
PeteGoo / Send-UdpDatagram.ps1
Last active July 23, 2024 13:28
Sending UDP datagrams in powershell
function Send-UdpDatagram
{
Param ([string] $EndPoint,
[int] $Port,
[string] $Message)
$IP = [System.Net.Dns]::GetHostAddresses($EndPoint)
$Address = [System.Net.IPAddress]::Parse($IP)
$EndPoints = New-Object System.Net.IPEndPoint($Address, $Port)
$Socket = New-Object System.Net.Sockets.UDPClient
@DrDougPhD
DrDougPhD / template.py
Last active February 1, 2023 17:11
Skeleton for Python command line script, including argparse and logging
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
SYNOPSIS
python SCRIPT.py [-h,--help] [-v,--verbose]
DESCRIPTION
@hdml
hdml / custom-ssl-cert-rdp.md
Created April 19, 2017 21:24
Custom SSL Certificate for Windows RDP Service

##Custom SSL Certificate for Windows RDP Service

Requirements

  • Windows 8+ or Server 2012+
  • Certificate with private key (*.p12)
  • Intermediate CA certificate (*.cer)
  • Administrative rights to modify the certificate store
@jerblack
jerblack / Elevate when needed in Go.md
Last active May 19, 2024 09:08
Relaunch Windows Golang program with UAC elevation when admin rights needed.

I'm buiding a command line tool in Go that has an option to install itself as a service on Windows, which it needs admin rights for. I wanted to be able to have it reliably detect if it was running as admin already and if not, relaunch itself as admin. When the user runs the tool with the specific switch to trigger this functionality (-install or -uninstall in my case) they are prompted by UAC (User Account Control) to run the program as admin, which allows the tool to relaunch itself with the necessary rights.

To detect if I was admin, I tried the method described here first:
https://coolaj86.com/articles/golang-and-windows-and-admins-oh-my/
This wasn't accurately detecting that I was elevated, and was reporting that I was not elevated even when running the tool in CMD prompt started with "Run as Administrator" so I needed a more reliable method.

I didn't want to try writing to an Admin protected area of the filesystem or registry because Windows has the ability to transparently virtualize those writes