Showing posts with label *nix. Show all posts
Showing posts with label *nix. Show all posts

Friday, July 20, 2007

"Automate Installation of Web Server in openSUSE 10.2 (installs Apache, MySQL, and PHP) - bash script"

A nice script written by Scott Morris, good for lazy/newbie. Full details at http://www.suseblog.com/?p=240

http://www.suseblog.com/install-lamp-stack.sh.tar.bz2 (tar -jxvf install-lamp-stack.sh.tar.bz2)

#!/bin/sh
# Bash script to install a lamp stack on an opensuse 10.2 system.

printf "##############################################################################
##\n"
printf "INSTALL SCRIPT FOR APACHE, MYSQL, AND PHP ON openSUSE 10.2\n"
printf "by Scott Morris (2007-06-21)\n"
printf "http://www.suseblog.com/\n\n"
printf "##############################################################################
##\n"

# Make sure we are root.
if [ "$EUID" != "0" ]; then
echo "You must have root privileges to run this script!"
exit 1
fi

printf "\n############################################################################
####\n"
printf "Installing Apache, MySQL, and PHP...\n"
printf "##############################################################################
##\n"

yast -i apache2-mod_php5 php5 php5-bz2 php5-gd php5-iconv php5-mbstring php5-mcrypt ph
p5-mysql php5-snmp php5-zlib mysql mysql-client mysql-devel mysql-shared perl-DBD-mysq
l apache2 apache2-mod_perl apache2-prefork libapr-util1 libapr1 php5-pdo

printf "\n############################################################################
####\n"
printf "Starting Apache and MySQL...\n"
blah@winnt:/tmp/attack_lab> vim install-lamp-stack.sh
blah@winnt:/tmp/attack_lab> cat install-lamp-stack.sh
#!/bin/sh
# Bash script to install a lamp stack on an opensuse 10.2 system.

printf "################################################################################\n"
printf "INSTALL SCRIPT FOR APACHE, MYSQL, AND PHP ON openSUSE 10.2\n"
printf "by Scott Morris (2007-06-21)\n"
printf "http://www.suseblog.com/\n\n"
printf "################################################################################\n"

# Make sure we are root.
if [ "$EUID" != "0" ]; then
echo "You must have root privileges to run this script!"
exit 1
fi

printf "\n################################################################################\n"
printf "Installing Apache, MySQL, and PHP...\n"
printf "################################################################################\n"

yast -i apache2-mod_php5 php5 php5-bz2 php5-gd php5-iconv php5-mbstring php5-mcrypt php5-mysql php5-snmp php5-zlib mysql mysql-client mysql-devel mysql-shared perl-DBD-mysql apache2 apache2-mod_perl apache2-prefork libapr-util1 libapr1 php5-pdo

printf "\n################################################################################\n"
printf "Starting Apache and MySQL...\n"
printf "################################################################################\n"

/etc/init.d/apache2 start
/etc/init.d/mysql start

printf "\n################################################################################\n"
printf "Adding Apache and MySQL to boot sequence...\n"
printf "################################################################################\n"

chkconfig -a apache2
chkconfig -a mysql

printf "\n################################################################################\n"
printf "Status of Apache and MySQL...\n"
printf "################################################################################\n"

/etc/init.d/apache2 status
/etc/init.d/mysql status

printf "\n################################################################################\n"
printf "You must now run the following command to initialize your MySQL root password:\n"
printf "/usr/bin/mysqladmin -u root password 'new-password'\n"
printf "/usr/bin/mysqladmin -u root -h `hostname`.`dnsdomainname` password 'new-password'\n"
printf "Note that unless you've set it up to be different, your web root is here:\n"
printf "/srv/www/htdocs\n"
printf "################################################################################\n"

Wednesday, December 27, 2006

Get your dsniff working on Slackware

Surely everyone has heard dsniff, an evil set of 31337 network tools. I finally grab a copy and wanna give it a try, but traditional ./confugre && make && make install didn't get it work. Couple hours googling took me a patch made by Sined , someone claimed it works while it didn't work on my slack box.. well, maybe it is for other distr or I have something missing (I guess I don't) , I got no clue what changes he made, neither able to google a solution works for me. So I figured out this simple dirty way, hope this helps for folks who facing the same problems.

www.packetfactory.net is down at the moment, I grabed a copy from http://www.enzotech.net/dsniff.html (Don't use ones on sf -outdated)
libnids-1.16-fixed-FC.tar.gz
libnet-1.0.2a-fixed-FC.tar.gz

After installing libnet and libnid,

insistkool@foo:~/dsniff$ ./configure
insistkool@foo:~/dsniff$ make
This produces bunch of compilation errors

----------------------------------------------------------------------------
./sshcrypto.c:25: error: field `key' has incomplete type
./sshcrypto.c:30: error: syntax error before "des_key_schedule"
./sshcrypto.c:30: warning: no semicolon at end of struct or union
./sshcrypto.c:31: warning: data definition has no type or storage class
./sshcrypto.c:32: error: syntax error before '}' token
./sshcrypto.c: In function `blowfish_encrypt':
./sshcrypto.c:131: error: `BF_ENCRYPT' undeclared (first use in this function)
./sshcrypto.c:131: error: (Each undeclared identifier is reported only once
./sshcrypto.c:131: error: for each function it appears in.)
./sshcrypto.c: In function `blowfish_decrypt':
./sshcrypto.c:143: error: `BF_DECRYPT' undeclared (first use in this function)
./sshcrypto.c: In function `des3_init':
./sshcrypto.c:153: error: dereferencing pointer to incomplete type
./sshcrypto.c:156: error: dereferencing pointer to incomplete type
./sshcrypto.c:157: error: dereferencing pointer to incomplete type
./sshcrypto.c:160: error: dereferencing pointer to incomplete type
./sshcrypto.c:162: error: dereferencing pointer to incomplete type
./sshcrypto.c:164: error: dereferencing pointer to incomplete type
./sshcrypto.c:165: error: dereferencing pointer to incomplete type
./sshcrypto.c:166: error: dereferencing pointer to incomplete type
./sshcrypto.c: In function `des3_encrypt':
./sshcrypto.c:176: error: dereferencing pointer to incomplete type
./sshcrypto.c:176: error: dereferencing pointer to incomplete type
./sshcrypto.c:178: error: dereferencing pointer to incomplete type
./sshcrypto.c:178: error: dereferencing pointer to incomplete type
./sshcrypto.c:178: error: `DES_ENCRYPT' undeclared (first use in this function)
./sshcrypto.c:179: error: dereferencing pointer to incomplete type
./sshcrypto.c:179: error: dereferencing pointer to incomplete type
./sshcrypto.c:179: error: `DES_DECRYPT' undeclared (first use in this function)
./sshcrypto.c:180: error: dereferencing pointer to incomplete type
./sshcrypto.c:180: error: dereferencing pointer to incomplete type
./sshcrypto.c: In function `des3_decrypt':
./sshcrypto.c:189: error: dereferencing pointer to incomplete type
./sshcrypto.c:189: error: dereferencing pointer to incomplete type
./sshcrypto.c:191: error: dereferencing pointer to incomplete type
./sshcrypto.c:191: error: dereferencing pointer to incomplete type
./sshcrypto.c:191: error: `DES_DECRYPT' undeclared (first use in this function)
./sshcrypto.c:192: error: dereferencing pointer to incomplete type
./sshcrypto.c:192: error: dereferencing pointer to incomplete type
./sshcrypto.c:192: error: `DES_ENCRYPT' undeclared (first use in this function)
./sshcrypto.c:193: error: dereferencing pointer to incomplete type
./sshcrypto.c:193: error: dereferencing pointer to incomplete type
make: *** [sshcrypto.o] Error 1

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

You can see err mainly caused by the failure to locate several function calls (des_key_schedule,DES_ENCRYPT, DES_DECRYPT etc). Be aware dsniff heavily relies on libnet, libnid and openssl (and few more)

insistkool@foo:~/dsniff$ cp sshcrypto.c sshcrypto.c.orig
insistkool@foo:~/dsniff$ vi sshcrypto.c
remove the space when you edit your file
15 #include <>
16 #include <>
17
18 #include <>
19 #include <>
20 #include
21
22 #include "sshcrypto.h"

So, we can tell compiler where these headers locate

15 #include <>
16 #include <>
17 #include <>
18 #include <>
19 #include <>
20 #include <>


All rite, now simply:
insistkool@foo:~/dsniff-2.3$ make
insistkool@foo:~/dsniff-2.3$ su -c 'make install'

Well, even I am on slackware, I think it will works just fine on other distributions. Lesson of the day - Don't google before read through give away message and get my hand dirty!

Saturday, December 16, 2006

How to install Slackware 11.0 in VMWare 5.5 on Windows XP?

Slackware 11 is out! All slackware user must be great to see this long waited version (Yes, I am a slacker ^^)

To feel the new slackware, I decided to install it in VMware on latop.

My Software:
Compaq Laptop Presario v4400
VMWare WorkStation 5.5 build-29772
Slackware 11.0

For those whom curious its new features and change, please review official change log at http://www.slackware.com/announce/changes11.0.php


First we grap a copy of Slackware ISO (FTP, HTTP, BitTorrent).
New slackware contains 6 CDs.
CD 1 base packages
CD 2 KDE
CD 3 KDEI (you need this if you are not English speaker)
CD 4-6 Source Code

Choose the appropriate CD according to your need. I downloaded the first 2 CDs with BitTorrent since I don't need GUI language pack and source code. If you are new to slackware, please go through the tutorials provided below.

p.s: Always verify md5sum, some ISO
A windows based md5sum can be reached http://www.md5summer.org/download.html

Fire up VMWare, create a new "Virtual Machine" -> Typical -> Linux -> Other Linux 2.4.x kernel (Slackware 11 uses 2.4.33.3) -> Save to wherever you like-> NAT (or bridge if you like, I chooce NAT at this case)

One trick here is VMWare uses SCSI by default, this needs couple more steps during installation. Thus, I change it to IDE by removing and adding in the "Edit virtual machine settings" section. Now, you need to tell VMWare to use "Physical drive" and certainly insert the CD 1. Till here, you are done for VMWare setup, time to installation.

First of all, change Boot sequence to boot from CD-ROM, all the way "Enter" and type in "root".
Now, you need to partition your hard drive, we use cfdisk /dev/hda (or fdisk) because it is simpler than fdisk.


You need to design your partition, here is my partition table (8 G):

512 Mb root partition (primary partition)
The root filesystem, contains system software and libraries, configuration data (/etc), local state data (/var) and all other filesystems are mounted under it.

Extended partition utilizing the rest of the disk
We then create logical drives on the extended partition.

512 Mb swap partition (logical drive)
Note that you probably don't need a swap partition that large but I like the extra insurance and I have plenty of space. It allows me to work on absolutely huge files, and provides extra memory addressing in the event of some sort of race condition. 256 Mb should probably be enough swap though, if disk space is tight.

4 Gb partition for /usr (logical drive)
Most all of your software and libraries get installed in /usr. It is useful to have a large partition for this.

1.5 Gb partition for /opt (logical drive)
"Optional" software can be installed here. For example, KDE will be installed to /opt/kde. I install some other software to /opt as well.

2 Gb (roughly) for /home (logical drive)
We use what is leftover, for /home. This is where the user directories are, and where users will store personal files. You may also install some software to /home if desired. I do, and I keep build directories there as well.

You might be interested in the following articles from Slackware FAQ:
How should I partition my hard disk?
How much swap space should I use?

Just follow the instructions, make your partitions.

You will be prompted after "write" partitions, "setup" your machine now.
root@slackware:/#setup

Scroll down to "ADDSWAP", you should see something like the below image after "SWAP SPACE DETECTED".

Choose/dev/hda1 as /root (follow table above), format the file system as "reiserfs". For the rest of partitions, perform the same procedure and eventually we see

You should be prompted to "select Slackware Installation source", CD is our choice. Then you need to pick your desired packages


After choose your desire packages, we simply perform a full installation. (You can always remove unwanted packages later)

you will be asked to "Install Linux Kernel". Again, we choose CD.


Be aware that all the options you made here can be modified later, so don't worry if you make any mistake.
Now we on the stage of "Enable Hotplug/VDEV" (This typically loads /etc/rc.d/rc.hotplug), we choose "No" and choose "simple" for LILO. The rest are pretty straightforward, I am sure any can figure out on his/her own. In the rest installation stages, you will be asked to configure video resolution, LILO destination (MBR typically), mouse configuration, GPM, Network configuration,

startup services, default window Manager for X (Note: GNOME is not available any more due to "hard to maintain", but you can download DropLineGNOME from http://droplinegnome.org/ if you insist on GNOME) and root password set up.

Till now, you are all set. Simply "reboot", then you will see the lovely login prompt.

Now, it is highly recommended to add a new less privileged user (adduser / useradd) .
Also run `alsaconf` to enable sound detection, `startx` to start GUI.

And I think I should mention slackware package management tool for those whom not are familiar with Slackware.

(You need "root" to run the following commands)
pkgtool - Menu-based package tool
installpkg - install a new package
removepkg - remove a package
upgradepkg - upgrade a pakcage
syntax: upgradepkg oldpkg%newpkg

For other package command (explodepkg etc, please review slackware handbook )
Installed package information store at /var/log/packages

Tons packages can be found at http://www.linuxpackages.net/
Official slackware package: http://packages.slackware.it/

"few" great slackware tutorial and tips can be found here (Yes, I said "few")
Excellent "free" slackware Book
http://www.slackbook.org/#book

Nice brief overview of slackware 11
http://linuxhelp.blogspot.com/2006/10/brief-look-at-slackware-110.html

Lots of useful links, articles and tips
http://www.userlocal.com/tips/tips.php

Slackware tips & tricks by Jack S.La
http://members.cox.net/laitcg/new/

Slackware Bible
http://www.slackersbible.org/?q=node/115


Final word:
Slackware is undoubtedly a great distribution (stable, simple, most Unix like, fast, secure...etc), my main intention to write this tutorial is to guide novice step into the world of Slackware. Drop me a note if you have any comment!

Thursday, December 14, 2006

Finish your work more efficiently

With linux's built in tool, we can do our work more efficiently. For instance, we want to create 50 user directories, tons way can do the task.

a perl version:
#!/usr/bin/perl

foreach i (1..50)
{
mkdir("user$_",0744);
# or use the system() function
System(`mkdir user$_");
}

while we can do this with shell, but it only fits :
for i in {1,2,3,4,5,6,7}; do mkdir user$i;done

Perl liner seems to be the best solution for this kind of task (only one line and we can set permission, isn't it great!)

perl -e 'for(1..6) {mkdir("user$_",0744)}'

Of course perl is not only option, python, ruby, C or whatever you like can do a good job. A lot of folks would rather spend whole of time on begging around for 'automated' software, hack up your brain, hack your system, answer is always there for you.

Set up mysql 5.0.24 in slackware 11

It is a bit awkward to set mysql up in slackware, unlike redhat or other distributions does the whole work for you, slackware needs couple more steps. Here is how I set it up

$su -
$mysql_install_db
$chown -R mysql:mysql /var/lib/mysql
$chmod +x /etc/rc.d/rc.mysqld
$/etc/rc.d/rc.mysqld start

Then on another terminal, login with user belong to user group or root

$mysql
mysql>

How to install postgres 8.2 on slackware 11

Took me sometime to figure out postgres 8.2 installation on slackware 11
Here is how:
Grep a source copy of postgres from http://www.postgresql.org,

./configure
gmake
su
gmake install
adduser postgres
chown postgres /usr/local/pgsql/data
chown postgres /usr/local/pgsql/data
su - postgres
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >logfile 2>&1 &
/usr/local/pgsql/bin/createdb test
/usr/local/pgsql/bin/psql test


riped form http://www.postgresql.org/docs/8.2/interactive/install-short.html

An easy way is to download postgres package from http://www.linuxpackages.net,
installpkg postgres_xx.tgz

Sometimes you get error message like "fatal: role 'insistkool' does not exist", do:
$su
$createuser -U postgres
Enter name of role to add: insistkool
Shall the new role be a superuser? (y/n) y

$initdb -D ~/data
$postmaster -D ~/data
psql insistkool

Metasploit 3 needs postgres database to perform auto exploitation, so it is highly recommended to install postgres on your machine for testing

Monday, October 16, 2006

*nix commands

Common daily use commands (to me ^^)
#show all system info
uname -a

#check distributions
cat /etc/*issue
cat /etc/*release*

#check who is online and ip
w

#Check username and working directory
cat /etc/passwd

#Get ip
ifconfig {eth0 etc}

#You know what this is
cat /etc/shadow

#find a file
locate file.ext

#find machine on the subnet
arp -a

#compile c code
gcc in_file -o out_file

#change file permission, x -[1-9]
chmod xxx filename

#show running process
ps aux

#calculate MD5 sum for every file on the system (assume md5sum is on the system)
find / -type f -xdev -exec md5sum -b {} \;

#find readble files
find / -type f -perm -4 -print 2> /dev/null

#find writable files
find / -type f -perm -2 -print 2> /dev/null

#find system time and date stamps
find / -printf "%m;%Ax;%AT;%Tx;%TT;%Cx;%CT;%U;%G;%s;%p\n"

#display system variables
set

#echo current path
echo $PATH

#clean screen (windows cls)
clear

#dump kernel modules
lsmod

#check mouted file sys
mount/df

#Check patch level for RedHat 7.0
rpm -qa

#list Open Files
lsof (lsof `which file`)

#hardware info
dmesg

#usual place for logging
cat /etc/syslog.conf

#how can we miss this, this can be couple pages of essay,brief example
grep str *
grep -r -i "\-a"

#check current user info
id

#figure out how long the host is up
uptime

#some system hardware info
cat /proc/meminfo
cat /proc/cpuinfo