Showing posts with label tools. Show all posts
Showing posts with label tools. Show all posts

Sunday, November 4, 2012

"Borrowing" A Screen Session

GNU Screen is a tool that most everyone reading this will be aware of.  In a nutshell, it's a terminal multiplexer, that is, it allows multiple virtual terminals to be brought up in one screen session.  Very useful when you're on the terminal.

Another purpose that is used quite often is to allow long running scripts to run on a remote server, without having to worry about your SSH session getting disconnected.  One would simply start a screen session, run their script, and detach from the screen session, leaving the script to do it's work.

This can occasionally be a problem when one system administrator has started a long running process, and for whatever reason, another system administrator needs to get into the screen session, when it's owner isn't present.  Attempting to su user, then attach to the screen session will lead to the following error:


[14:43:06] [peter@server ~]$ sudo su user
[sudo] password for peter: 
[14:43:45] [user@server /home/peter]$ screen -l
Cannot open your terminal '/dev/pts/2' - please check.
[14:43:53] [user@server /home/peter]$

A quick check of the permissions of /dev/pts/2 reveals the problem:


[14:43:53] [user@server /home/peter]$ cd /dev/pts/
[14:51:42] [user@server /dev/pts]$ ls -lsa 2
0 crw--w---- 1 peter tty 136, 2 2012-11-04 14:51 2

As we can see, the terminal I'm connected to is owned by my user, not effective user that we assumed with su user.  One solution would be to chmod +w /dev/pts/2, but allowing other users to connect to our pts device poses a security risk.  Enter script.

Script is used to create a typescript recording of everything that happens in a terminal, as long as script is running.  It will connect to a new tty device when it is called:


[15:00:20] [user@server ~]$ script test
Script started, file is test
[15:00:25] [user@server ~]$ tty
/dev/pts/3
[15:00:32] [user@server ~]$ ls -lsa /dev/pts/3
0 crw--w---- 1 user tty 136, 3 2012-11-04 15:00 /dev/pts/3

As you can see, by calling script, we have obtained a new pts device, and it's owned by user, not by peter.  This means that we can now screen -d -r to attach to user's screens, even in his absence.

One last note:  If you don't have a purpose for the typescript file that is generated by script, just give it /dev/null as an output file:  script /dev/null, which will throw away the typescript.

Saturday, November 3, 2012

protosho v1.0 (almost)

Admittedly, I haven't been playing with Dettu[xX] too much over the last month, but I did come back to a stagnant code project that I started in late September or early October, and did a bit of general cleanup and prep work towards being something thats fit for (very adventurous) human consumption...

It doesn't have a working installer (I'd advise leaving Makefile.PL well alone unless you know what you're doing... it's not complete), it doesn't have any documentation other than the comments in the code, but if you can get it to run, it does it's job.

So, for the moment that no-one has been waiting for, I give you protosho:

https://github.com/protoCall7/protosho

This little baby is a CLI::Framework based SHODAN interface for the commandline.  It's written 100% in Perl 5.14, it's licensed under the BSD 3-clause, and at the moment, it kind of sucks.  But I've had a ton of fun playing with the results that it cranks out, so for anyone else out there who likes to tinker with Perl, or has a need for some SHODAN on the CLI, or is just feeling techno-masochistic, grab a git clone of it, and leave me a comment here, or on the Github issues board, and I'll help you through getting it installed.

In the meantime, you should also check out SHODAN @ http://www.shodanhq.com

proto

Wednesday, December 1, 2010

Loopback Filesystem

Ok, so it took quit a bit of expirimentation and FM reading, but here's the lowdown on creating loopback filesystems:

Create a file to hold the system, in my case, it's gonna be 10 megs:

peter@slacktop:~$ dd if=/dev/zero of=/home/peter/fsfile bs=1k count=10240
10240+0 records in                                                     
10240+0 records out                                                    
10485760 bytes (10 MB) copied, 0.0606135 s, 173 MB/s

Next set up the loopback system and point it at your spiffy new file:
peter@slacktop:~$ sudo /sbin/losetup /dev/loop0 /home/peter/fsfile

From here you can create and mount your filesystem:

peter@slacktop:~$ sudo /sbin/mkfs.ext2 /dev/loop0
mke2fs 1.41.8 (11-July-2009)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
2560 inodes, 10240 blocks
512 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=10485760
2 block groups
8192 blocks per group, 8192 fragments per group
1280 inodes per group
Superblock backups stored on blocks:
        8193

Writing inode tables: done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.


peter@slacktop:~$ sudo mkdir /mnt/lo
peter@slacktop:~$ sudo mount /dev/loop0 /mnt/lo

Tada... loopback filesystem.

Tuesday, September 9, 2008

Rediculous...

I really should have noticed that the first disk had a lower block count than the other 7... Bad media right out of the box. Lets try again...
hackserv:/home/proto/Desktop# dd if=dettuxx_disk01.img of=/dev/fd0
2880+0 records in
2880+0 records out
1474560 bytes (1.5 MB) copied, 100.915 seconds, 14.6 kB/s
Ahhh... much better... now to see if she boots :-P

dd

Not that anyone really needs to see how the dd command works across all 8 disks, but here you go.
hackserv:~# dd if=./dettuxx_disk01.img of=/dev/fd0
2847+1 records in
2847+1 records out
1458144 bytes (1.5 MB) copied, 101.165 seconds, 14.4 kB/s
hackserv:~# dd if=./dettuxx_disk02.img of=/dev/fd0
2880+0 records in
2880+0 records out
1474560 bytes (1.5 MB) copied, 101.119 seconds, 14.6 kB/s
hackserv:~# dd if=./dettuxx_disk03.img of=/dev/fd0
2880+0 records in
2880+0 records out
1474560 bytes (1.5 MB) copied, 101.119 seconds, 14.6 kB/s
hackserv:~# dd if=./dettuxx_disk04.img of=/dev/fd0
2880+0 records in
2880+0 records out
1474560 bytes (1.5 MB) copied, 102.521 seconds, 14.4 kB/s
hackserv:~# dd if=./dettuxx_disk05.img of=/dev/fd0
2880+0 records in
2880+0 records out
1474560 bytes (1.5 MB) copied, 101.321 seconds, 14.6 kB/s
hackserv:~# dd if=./dettuxx_disk06.img of=/dev/fd0
2880+0 records in
2880+0 records out
1474560 bytes (1.5 MB) copied, 101.518 seconds, 14.5 kB/s
hackserv:~# dd if=./dettuxx_disk07.img of=/dev/fd0
2880+0 records in
2880+0 records out
1474560 bytes (1.5 MB) copied, 101.314 seconds, 14.6 kB/s
hackserv:~# dd if=./dettuxx_disk08.img of=/dev/fd0
2880+0 records in
2880+0 records out
1474560 bytes (1.5 MB) copied, 101.516 seconds, 14.5 kB/s
hackserv:~#

And for thoes who don't know... A short excerpt from "man dd" (RTFM!)

NAME
dd - convert and copy a file

SYNOPSIS
dd [OPERAND]...
dd OPTION

DESCRIPTION
Copy a file, converting and formatting according to the operands.