chroot shell tutorial

let's say you want a user of your (linux) server to have no access to anything you don't want him/her to use..
but you do want them to be able to log in and do their thing...
you'll need to root jail (chroot) the user.
there are lots of tutorials about chroot and also chrooted shells, but I couldn't find a good one, so I wrote one down while working my way thrue the othere tutorials and howto's..
hope you like it !!

disclaimer:
reading and following any or all steps in this tutorial is at your own risk.
I am not responsible for your stupidity !


his tutorial should work on all linux distributions, but i've only tested it on slackware (9.0, 9.1, 10, 10.1 and 10.2)

you'll need the following programs (wich are possibly not installed):

/usr/bin/sudo
/usr/sbin/chroot

If you can't seem to find or install these, this tutorial is not for you !!

all thrue the tutorial you'll see bold italic lines.. they are supposed to be executed by you
whoami
if that didn't say root. you'll need to become root.
su

in this example the user "luser" will be added and jailed ..
you'll need to be super user (root) to do all this..

let's start by adding the user:
useradd -d /tmp -s /bin/chrootshell luser
this adds the user luser with home folder /tmp with shell
/bin/chrootshell

now set his password:
passwd luser

make his home dir:
mkdir /home/luser


now we need to make his shell..
use your favorite editor to paste the following in /bin/chrootshell
#!/bin/bash

# chrootshell spawns chroot shell
#
# (c) 2003-2005 Anne Jan Brouwer
# GNU GPL

if [ "$1" = "-c" ]
then
i=0
PARAMETERS=""
for parameter in $*
do
if [ $i -gt 0 ]
then
PARAMETERS="$PARAMETERS $parameter"
fi
let i++
done
sudo /usr/sbin/chroot /home/$USER /bin/su - $USER -c "$PARAMETERS"
else
sudo /usr/sbin/chroot /home/$USER /bin/su - $USER
fi


make the "chrootshell" executable..
chmod +x /bin/chrootshell

now, let's go and make the chroot root ;)
we go to the users home dir, wich will become his root
cd /home/luser
note: we will be staying in for the rest of this tut !!!

make the most important folders..
mkdir bin dev etc home lib tmp usr

make the users chrooted home dir
mkdir home/luser
chown luser:users home/luser

make the chrooted tmp dir usable
chmod 777 tmp
chmod +t tmp

let's make the chrooted passwd file
grep root /etc/passwd >> etc/passwd
now we'll need to edit the passwd file to change the lusers chrooted shell and path..
fire up your favorite editor to edit the newly created passwd file.
the line should look a little like this:
luser: x:1020:100::/tmp:/bin/chrootshell
change it to:
luser: x:1020:100::/home/luser:/bin/bash
not that 1020 is the users ID and is propably some other number on your
puter.. don't change it to 1020 just because it said 1020 in my example ok ;)

now we'll make the chrooted group file
grep root /etc/group >> etc/group
grep users /etc/group >> etc/group

we'll copy the standard /etc/profile and needed files you could chose to edit these
cp /etc/profile etc
cp /etc/DIR_COLORS etc
cp /etc/HOSTNAME etc

we'll need to make some much needed devices
mknod -m 0666 dev/tty c 5 0
mknod -m 0644 dev/urandom c 1 9
mknod -m 0666 dev/null c 1 3

let's now make some usefull (compatibility) links and folders..
ln -s bin usr
ln -s lib usr
ln -s lib usr/libexec
mkdir usr/local
ln -s bin usr/local
ln -s lib usr/local
and make the terminfo (needed for a lot of programs) available in the root jail.
mkdir usr/share
cp -r /usr/share/terminfo usr/share

now for the realy fun part...
you'll have to find out some stuff:

1. what do you want the user to be able to use
2. what library's do these executables need
3. what other files will the user be needing

1. what do you want the user to be able to use

the user will need a shell (bash)
the user will need su (because the chrootshell script depends on it)
the user will need basic tools (cp, cat, ls, rm, mv etc.).
you'd want the user to have some other tools (vi, pico, whoami etc..)
you'd like for the user to have dircolors and id (needed if you want to use the standard etc/profile)

copy these files to the users chrooted bin dir
cp `which bash` `which su` `which cp` `which ln` `which ls` `which rm` `which mv` `which cp` `which du` `which cat` `which less` `which vi` `which pico` `which whoami` `which dircolors` `which id` bin
note: the `which bash` part returns the full path of bash (/bin/bash) etc..

2. what library's do these executables need


the command ldd is realy usefull here..
let's take bash for example:
root@server~# ldd `which bash`
libtermcap.so.2 => /lib/libtermcap.so.2 (0x4001b000)
libdl.so.2 => /lib/libdl.so.2 (0x40020000)
libc.so.6 => /lib/libc.so.6 (0x40023000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)


and copy all the needed libs for each of the programs you chose in step 1 to the chrooted lib dir..

let's first do so for bash
cp /lib/libtermcap.so.2 /lib/libdl.so.2 /lib/libc.so.6 /lib/ld-linux.so.2 lib
next the one (on my system) missing for su
cp /lib/libcrypt.so.1 /lib/libnss_compat.so.2 /lib/libnss_files.so.2 lib
note that ldd doesn't see that libnss is needed, it is!!
next the ones for ls (only the ones not allready copied ofcourse ;))
cp /lib/librt.so.1 /lib/libpthread.so.0 lib
etc...
cp /lib/libncurses.so.5 lib
cp /lib/libresolv.so.2 lib

3. what other files will the user be needing

well this depends on what kind of programs the user is allowed to execute..
there's no real telling what you'll have to give the user to be content..
wait a minute !! the user has to be content with what you give him/her !!


the last step is to add the user to the sudoers file..
open the /etc/sudoers file with your favorite editor or use
visudo
add the line:
luser ALL= NOPASSWD: /usr/sbin/chroot /home/luser /bin/su - luser*
save and exit

now to check it out.. try and log in as the newly created luser
ssh -l luser localhost


A lot more info on chroot logins

A nice derived paper can be found at rootshellsecurity.com

Another system I'm gonna have to check out is jailkit..


Copyright (c) 2003-2005 by Anne Jan Brouwer (the_JinX).
This work is licensed under a Creative Commons License.
Attribution-ShareAlike 2.0 or later

reference:http://intmainvoid.nl/

Trinity Rescue Kit 3.4 released



After more than a year of development, developer Tom Kerremans has announced the release of version 3.4 of the Trinity Rescue Kit (TRK). TRK is a Live distribution – bootable via a LiveCD, LiveUSB or over a network – that's based on Mandriva Linux and is specifically aimed at recovery and repair operations for both Windows and Linux systems. For example, it includes a number of tools for recovering deleted files, resetting passwords and cloning drives.
Trinity Rescue Kit 3.4 uses the latest 2.6.35 Linux kernel and features an updated, easy to use scrollable text menu that provides access to its most commonly used features. Using the NTFS-3G read/write driver, TRK includes full NTFS file system write support. Other features include an application for removing various temporary files from a system, full proxy server support and several updates to the included packages. Five anti-virus programs with online update capabilities are included, integrated into a single uniform command-line, as well as two rootkit detection utilities.
More details about the release can be found in the official release announcement and in the change log. Trinity Rescue Kit 3.4 build 367 is available to download as a 146MB LiveCD from the project's site and online documentation is provided.

reference: http://www.h-online.com/open/news/item/Trinity-Rescue-Kit-3-4-released-1059476.html

PSP Hacking (Softmodding your battery)

This was the tutorial i used when i was first getting into PSP hacking. I did not write this myself, it came origionally from a man named Ben Heck which can found at Ben Heck's Official Site. Most tutorials tell you that you need a second PSP with a custom firmware installed (homebrew) to create a pandora battery and magic memory stick for the PSP that you which to Unbrick. If you dont have access to a second unbricked PSP then this tutorial will help you out like it did for me. I would write this tutorial myself, but most all of the information i have on this method i aquired from this tutorial anyways, so it only makes sence to share the origional.




We will still start off with Q/A (Questions/Answers)

Q)What is Pandora's Battery?
A)Pandora's Battery is a utility that utilizes your memory stick and battery to hack your psp.

Q)There are already a lot of tutorials for this.....what makes yours any different?
A)On most of the tutorials it tells you that you require a psp that has 1.50 or a custom firmware. My tutorial doesnt require the use of a second psp! Just some spare time and a little skill.

Q)Is Pandora's Battery illegal?
A)Pandora's Battery is in no way illegal because it doesnt use any copy written material (rather it be from Sony or a 3rd party application)

Q)What is "Hardmodding"?
A)Hardmodding is a way or modifying something through hardware. (example: modifying a battery)

Q)Why did you update this post?
A)As listed above, i always receive mail because people don't understand some of the processes. So hopefully this newer version will sum things up and make it clearer.

Q)I Cant afford a new battery what can i do?
A)Read the "DA Time Machine section"

Q)Where have you been?
A)Around the world lol. I moved.....

Q)Whats with the pictures and videos?
A)Sorry if the quality isnt that good. If anyone feels they can do better, do so and i will add them and give them their props lol.

Well, with that out of the way, lets get started!!!!

We will now discuss how the tutorial is going to be organized (because organizations is a key factor in many great posts lol)
1)Questions and Answers
2)Materials Required
3)Process #1: Creating the Magic Memory Stick
4)Process #2: Creating the Magic Memory Stick with a bricked psp
5)Process #3: Moving the partitions
6)Process #4: Hardmodding the battery
7)Testing your battery
8)Running the files
9)Tips and Tricks
10)Final Questions
11)Information Links
12)Download Links
13)For Nerds ONLY (how this works)
14)Upgrading Custom Firmware
15)Error Fixing
16)Windows Vista
17)DA Time Machine (This covers how to bypass the ressurection.elf and how to use it)
18)Pictures/Videos

Now that we understand that, we can now continue with the guide. So first up is "Materials"
(NOTE: The materials will be organized by 1)Name and then by 2)Amount needed)

Materials:
----------
A psp (1)
A psp battery (2)
A memory stick pro duo with 512MB or more, NO LESS (1)
A mini USB or Memory Card Reader (1)
A computer with an internet connection (1)
A knife/exacto knife (1)
A needle, safety pin, tooth pick, etc (1)
Winrar (see Download Section)

Now i assume that these are common household material (if not you can buy them all at a walmart for about $50 or less)

Process #1: Creating the Magic Memory Stick
--------------------------------------------
(NOTE: this is for working psp's. so if your psp is bricked, you dont have to do this one. just go to the next one)
1)Turn on the psp and go into USB mode
2)Download Winrar (see download section) if you havent already
3)When your computer detects the psp, go to "My Computer"
4)Right-click on your psp's drive and select "Format"
5)Format the memory stick
6)Next download the "universal unbricker" (which is in the download section)
7)Place all the files inside of it onto your psp's drive. These files should include:
==three folders called "PSP", "kd", and "registry"
==three eboots called "150.pbp", "340.pbp", and "371.pbp"
==one bin file called "msipl.bin"

once done with that, move to "Process #3: Moving the Partitions"

Process #2: Creating the Magic Memory Stick with a bricked psp:
---------------------------------------------------------------
In order to do this, we are going to need a Memory card Reader/Writer.
1)Plug your Memory Stick in via Card Reader
2)Follow the above tutorial from step 2-7

Process #3: Moving the Partitions:
---------------------------------
(NOTE: Keep your memory stick in through USB or card reader)
1)Download the partition mover
2)Extract the folder "msinst" to your hard drive (C:\)
3)Go to "My Computer" and find your PSP drive letter (Removable Disk ?)
4)Go to "Start"
5)Go to "Run"
6)Type in "cmd" and press OK

from here, there should be a black and silverish white screen. If so, your all good and are ready to continue.

7)Type this in: "cd C:\msinst"
8)Next, type in "msinst ? msipl.bin" (remember No quotes) (also, replace ? with your removable disk letter)(also, use a capital letter to represent your drive. example: C:\msinst>msinst J msipl.bin)
9)It will show some stuff and give you 2 options. 1)Y=Yes 2)N=No........of course, press Y and then enter
10)You should receive a confirmation that the partitions were successfully moved

and thats it! your done with your magic memory stick and partition moving!!!!! That wasnt so hard now was it?
Now, lets continue!

Process #4: Hardmodding the battery:
------------------------------------
1)Take your battery and open it using a knife or exacto knife
2)look on the main board for the display "ICO4" or "CO4" (depending on your battery)
3)Now, take a needle or something like that and remove pin #5
here is a diagram: (NOTE: you can find pin #5 easily when the ICO4 or CO4 display is facing you!!!!)
__ (pin 4) __ (pin 8)
__ (pin 3) __ (pin 7)
__ (pin 2) __ (pin 6)
__ (pin 1) __ (pin 5)
a better diagram of it can be found on ben hecks page (see links)
4)After that, put your battery back together.

congratulations, you just softmodded your battery!!!!!

Testing your battery:
---------------------
Your will know if you successfully made your battery when:
1)you inert the battery and the green power LED comes on
if it doesnt come on, you did now make it correctly!

Running the files:
-----------------
Once your battery and your memory stick are being used at the same time, you will now have a "Pandora's Battery"
so.........................
1)put in your magic Memory Stick
2)Put in your softmodded battery
*if you see your wifi LED and memory stick LED blink, you have it working!!!!!!! as though in most occasions your screen wont light up but if it does, thats always good too*
3)When your LED's are don flashing, press "[]" (square) to dump your nand flash (just in case you brick. be warned, the file is anywhere from 32MB-64MB depending on your psp)
4)After that is done, you will be required reboot, so press X (cross) when your LED's are done flashing or when instructed to)
5)Re-put in your battery and the pandora menu will load
6)Press X (cross) to install 3.71M33
7)After thats done, you will need to reboot again (press X (cross) when instructed to or when the LED's are done flashing)
8)Now, remove your battery
9)Plug in your charger
10)Turn on the psp
11)Put in your battery
12)Remove the charger
13)And you should now be running 3.71M33!!!!!

Tips and tricks:
---------------
1)Run the v3 universal unbricker when your done so you can see the text (on slim psp's or fat)
2)Buy a new battery (if your cheap, see the 1st question on "Final Questions"
3)Remember NOT ALL homebrew is compatible with the psp slim!!

Final Questions:
---------------
(Q)Can i ever dual boot my XMB and my battery
(A)Yes! you can do this only one way. you need to buy a switch and solder on the + and - connector to the batter and to the switch. This will allow you to choose when you want to boot into pandora's battery or into your XMB (see links)

(Q)When i insert my softmodded battery, the psp turns on but i cant see anything
(A)Thats because your probably using a psp slim which in that case, just press X and then install the V3 unbricker

(Q)The light comes on but my MS LED and my wofi LED doesnt do anything
(A)This is a common problem when you dont follow the instruction EXACTLY, you have to re-create the magic memory stick

(Q)Did you create this?
(A)No, i did not. Ben Heck did and all details can be found on his site (see links)



It is also good to mention that this method is for the "fat" psp model, if you own a slim, lift the #4 pin instead of the #5 pin from the battery.


Download Links:
----------------
Partition Mover:http://www.ziddu.com/download/11123243/msinst.rar.html
Universal Unbricker: http://rapidshare.com/files/75256518/Pandora_Files_-_Move_to_the_root_of_your_memory_stick.rar.html