linux
"keyboard injection" under Linux
What to do if you want to pass some data into STDIN of some process,
and it doesn't accepts it?! One of the most (un)famous example is ssh;
who never tried to do a "echo password | ssh host"?!
So, you just want to inject characters as there were someone
typing them. Remember: TIOCSTI ioctl() call is your
friend 
Just google it to see what
it does. And now, some actually working code:
#!/usr/bin/perl -w
use strict;
use Fcntl;
use constant TIOCSTI => 0x5412;
unless (@ARGV >= 1) {
print "usage: $0 [vt] <input>\n";
exit;
}
my $vt = shift @ARGV;
my $buf = join '', <>;
&writevt ($vt, $buf) || die "can't write to $vt: $!\n";
exit;
sub writevt {
my ($vt, $buf) = @_;
sysopen (VT, $vt, O_RDONLY) || return 0;
for (my $i = 0; $i < length $buf; $i++) {
ioctl (VT, TIOCSTI, substr ($buf, $i, 1)) || return 0;
}
close (VT) || return 0;
return 1;
}
And this is how it works (Linux-specific!!!):
[stas@home stas]$ echo id | ./catvt.pl /dev/pts/0
id
[stas@home stas]$ id
uid=?????(stas) gid=?????(stas) groups=?????(stas)
Kinda awesome
|
stas » August 15, 2007 » 21:20
add new comment » 2956 reads
|
X11 FrontEnd for the Rio Utility

X11 FrontEnd for the Rio Utility v1.07 made by guys from the Snowblind Alliance. Surely not the best nor the most beautiful of all GUIs made to manage the famous Rio MP3 Player, but I tried to implement some of the ideas that the "real" managers doesn't implement. List of some "interesting" features:
- 2 windows side-by-side like in Norton Commander legacy managers
- treats M3U playlists as directories
- displays the space remaining on the device as you select files to upload
- current file & overall progress bars
- realtime display of the transfer speed
rio.exe is OK. You can download it here and test
for yourself! However, I would suggest you to use my Diamond Rio PMP300
FS-plugin for Total
Commander.P.S. - if you get problems downloading files with long names, apply the patch I provided below on the Rio Utility source (not XRio itself!) and recompile it.
|
stas » January 8, 2007 » 09:37
2 attachments » add new comment » 12258 reads
|
ACFTools (for X-Plane)
The Plane-Maker from X-Plane v7.x is fun and easy to use... Although I found it a bit limited to edit my planes' fuselage. 20 cross-sections aren't enough, sometimes. It would be nice to export the fuselage shape into any 3D-editor and fine-tune it there... This is exactly what my ACFTools are supposed to do. Please note that X-Plane v8.x is unsupported, unless you create & edit a v7 model and then import it to Plane-Maker v8. But I believe this isn't a problem: X-Plane v8 is able to use OBJ format files (which can be imported/exported by AC3D and Blender plugins) as parts of an aircraft, thus, extremely weird shapes are perfectly possible without even touching the ACF file.
Now, what exactly ACFTools does? It is able to process the file that stores all the aircraft data (except the textures), in the binary ACF format, and dump all the data in the human-readable TXT format. It is the same format as for Tony Gondola's ACF2Text utility, which inspirited my ACFTools. Then, ACFTools can extract the 3D model of the aircraft from this data, and export it in the AC3D format. After that you can edit the aircraft's shape as you want using AC3D and make the inverse process: from
.ac to .txt, and then from .txt to .acf. Here comes the brief set of ACFTools features:- Convert from ACF (aircraft) & WPN (weapon) formats to TXT format and vice-versa.
- Extract AC3D model from TXT file, along with wings and propellers (using the real airfoils!).
- Import AC3D model into TXT file (fuselage, nacelles, wheel fairings & external fuel tanks only)
ACFTools was written in Perl, thus it is able to work under Linux, MacOS & Windows. And it is Open-Source & highly modular, so you can modify it as you want, or use my functions for your own needs. When you start ACFTools, this is what you get at your console:
##############################################################################
[ACFTools v0.62a] Set of tools to play with ACF files outside of Plane-Maker
Perl script and modules coded by Stanislaw Pusep
Site of this and another X-Plane projects of mine: http://xplane.sysd.org/
Allows you to:
* export X-Plane (www.x-plane.com) aircraft data files to human-editable
plaintext format and 3D mesh editable in AC3D modeler (www.ac3d.org).
* import plaintext/3D mesh back to ACF file.
##############################################################################
Usage: acftools.exe[parameters]
o Commands:
-extract [DEF] : extract TXT from ACF (opt: using DEF definition)
-generate : generate ACF from TXT
-merge : merge body from AC3D file to TXT
o Parameters:
-acffile FILE : name of ACF file to process
-txtfile FILE : name of TXT file to process
-ac3dfile FILE : name of AC3D file to process
-noorder : DO NOT sort vertices while merging bodies
-noac3d : DO NOT generate AC3D
-(min|max)body N: write all bodies in specified range to AC3D
-force LIST : force extraction of bodies LIST (comma-separated N)
-normalize N : normalize wings to N vert/surface (N>=2 or no wings!)
o Notes:
* You can use abbreviations of commands/parameters (-gen or even -g
instead of -generate).
* The only required parameter for "extract" command is -acffile.
Both -txtfile and -ac3dfile are derivated from it.
* "generate" command and -txtfile has the same relation.
* By default "extract" uses the latest DEF file.
* "generate" doesn't need DEF at all (it is implicit in TXT)
* If file to be created already exists backup is made automatically.
o Examples:
acftools.exe --extract=ACF700 --acffile="F-22 Raptor.acf"
(extract 'F-22 Raptor.txt' from 'F-22 Raptor.acf')
acftools.exe -e -acf "F-22 Raptor.acf"
(same as above)
acftools.exe -me -ac3d ladar.ac -txt "F-22 Raptor.txt"
(merge *single* 3D body from 'ladar.ac' to 'F-22 Raptor.txt')
acftools.exe -g -txt "F-22 Raptor.txt"
(reverse operation; generate 'F-22 Raptor.acf' from 'F-22 Raptor.txt')
defs directory. By default, it is a ACF740.def,
which works for X-Plane v7.40 and later. You can specify any definition
file you want, as shown on the screen above. You can also write your
own definition files, if you have the structure specification. Note
that to convert TXT back to ACF, no definition is necessary, as the TXT
format itself holds all the data necessary to build the binary file.
The second thing is to specify the file that ACFTools should convert.
The name of the converted file and every of the intermediary files will
be generated from this name. When converting from ACF to AC3D formats,
TXT file is generated automatically. Please note that when you want to
put the edited aircraft part back into the .acf file, you must save this part as a .ac
separate file, then merge it into the TXT file, and after that convert
it into ACF! Yes, it would be nice to have a GUI to automate the entire
process, but I'm too lazy to do that! Anyway, may the source be with you

I strongly recommend you to read the
docs\README.txt file contained in the ACFTools package before you start using it!|
stas » May 10, 2006 » 01:09
3 attachments » 2 comments » 11174 reads
|
"ps auwx" faker
"Process Stack Faker" (psf for short) is able to hide the real executable name and it's parameters from the output of "ps auwx", "ps -ef" & "top"
(on UN*X machines), without any superuser privileges. Why should one
wish to hide the stuff he/she executes is a complete different topic 
Let's take a look at the options that psf itself accepts:
$ ./psf
Process Stack Faker (a.k.a. Fucker) v0.03
Coded by Stas; (C)opyLeft by SysD Destructive Labs, 1997-2003
Usage: psf [options] command arg1 arg2 ...
Where options can be:
-s string fake process name
-p filename file to write PID of spawned process - optional
-d try to start as daemon (in background, no tty) - optional
-l DO NOT exec through link (detectable by 'top'!!!) - optional
-u uid[:gid] (format just like in chown(1)) reset UID/GID - optional
-n priority renice process - optional
Example: psf -s "pine -i" -d -n 19 ./john -session:websrv
$
psf will execute "command arg1 arg2", and it will appear to "ps" & "top" utilities as "string". All other options are... Uhm, optional! They are only useful to detach processes not designed to run as daemons. "-l"
is a 'compatibility' switch that disables the weird trick used to
override the detection of the real filename by some process listers
(notably "top"). The default option may work unexpectingly on some systems (by the way, psf works fine on FreeBSD 4.3, Linux 2.4, NetBSD 1.5 & Solaris 2.7). To test psf, try this:$ psf -s "pine -i" sleep 30 &
[1] 440
$ ps auwx
...
stas 84 0.0 0.6 2012 1232 pts/0 S 19:12 0:00 bash -rcfile .bashrc
stas 440 0.0 0.1 1204 376 tty2 S 20:09 0:00 pine -i
stas 450 0.0 0.4 2544 816 tty2 R 20:12 0:00 ps auwx
...
"sleep 30" process was spoofed as "pine -i". Please note the white line between PIDs 440 and 450. This occurs because psf uses whitespace (0x20) characters to shift the original process arguments away from the visible area 
To understand how does
psf works and learn how to compile it, just read the comments inside the source.
|
stas » May 5, 2006 » 01:57
attachment » add new comment » 4790 reads
|
ttysnoop for kernel 2.6
ttysnoop is a small program made by Carl Declerck that allows an
administrator to snoop on login terminal through another. It worked until kernel 2.4 because they still with BSD-style pty's
support. Here it is a solution for 2.6.Screenshot:
SSH:
Is ttysnoop compatible withsshd? ttysnoop was created to work with inetd, however,
there is a way to make it work with sshd.First you will need the source code of the
sshd. Edit the file configure and add these lines:LOGIN_PROGRAM="/sbin/ttysnoops"
export LOGIN_PROGRAM
pathnames.h:// #ifndef SSHDIR
#define SSHDIR ETCDIR "/ssh"
// #endif
./configure --prefix=
/usr/sbin/sshd and put your new sshd in the
place. That should work. If you are using RedHat or Fedora Core you can try to use my
executable (see below).Bugs:
After log out, it doesn't remove the pseudo-terminal entry. Meaning people showed up as still logged in when they weren't.I use: who -u | grep -v ?
to see who really is on my system. I don't know how to solve it.
|
stas » May 4, 2006 » 13:09
3 attachments » add new comment » 7696 reads
|
rockin' PC speaker
. Thus, it is perfect for
communicating critical states. But the default system beep is quite
boring, and makes difficult to distinguish different events that are
being communicated. So, here's my humble attempt to make a highly
portable function that is able to play simple non-polyphonic music on
the PC speaker. I used it originally to advise when someone tried to
log in to my system through SSH daemon (thus the name "daemoniac" - demoniac
. It was tested (and worked fine!) under:
- DOS (DJGPP, Turbo C)
- Windows 9x/NT/2K/XP (Borland C, Microsoft Visual C, MinGW)
- Linux (gcc)
- FreeBSD (gcc)
demoniac will play Iron Maiden - Fear Of The Dark beginning. You can also compile it to play the simple "A#4 D#5 G5 A#5 G5 A#5" melody. Note that on UN*X systems, demoniac accesses hardware directly, and thus requires to run as root user. It's safe, through: it
won't accept any command line arguments and neither process environment
variables, so, at least, it can't be exploited with some buffer
overflow technique. For detailed instructions about compiling demoniac on
different compilers/systems, read the comments at the start of the
source. Note that my package provides all the binaries generated on
compilers/systems listed above.|
stas » April 20, 2006 » 02:06
attachment » add new comment » 5890 reads
|
knuckle cracker
This project is a response to the urge to make small changes to the big binary files. For text files, there are diff/patch utilities; and for big changes, rsync
is perfect. Now, if you're sharing something like a game mod,
where you need to swap a single bit inside a huge data file (just like
in a Hot Coffee Mod for GTA San Andreas , you're frequently forced to share the entire file. By the other side, if you need to update some
firmware glitch, why should you rewrite the entire flash chip?! So, here's my proposal.
bin_diff utility will compare two binary files and output a human-readable (and writable
script file, just like this:
[bb35cc23dda6737d181a63ea3203f0ff engine.dll]
50 "This program must be run under Win32\xd\xa$"
d60a EB
d77b 90 90
da3f E9
da41 1 0
ea44 90
# Patch length: 0000007A
#).
Several files may be patched by a single patch-script. The last string
in the last line is a hex value of the patch data length. It is useful
to make self-applicable patches.Then,
knuckle_cracker may be used to parse the
patch-script and apply modifications to the files. It will check the
MD5 checksum for each file automatically (and will refuse to patch unmatched files). You can also make the
self-applicable patches, concatenating the patch-script directly at the
end of the knuckle_cracker executable (following example works on UN*X systems, for Windows box, use any hex editor, it works just the same):cat knuckle_cracker engine.bin_patch > engine_patcher
bin_diff & knuckle_cracker are very portable: I tested them on Linux, FreeBSD (gcc) & Win32 (Borland C/CYGWIN/MinGW/MSVC).
P.S. - all sources has DOS line endings (CRLF), use
"unzip -aa knuckle_cracker.zip" to extract on UN*X systems.
|
stas » April 19, 2006 » 02:42
attachment » add new comment » 11946 reads
|






