Connect with us

HOW TO

How To Avoid SQL Injection Attacks

sql injection attacks
How To Avoid SQL Injection Attacks
In many ways, the popularity of programming languages such as PHP in web development are to blame for the prevalence of SQL injection attacks.

Many prominent websites, such as Facebook, were originally developed using PHP. This language is one in which the SQL injection attack has been a significant problem, but it’s far from the only language to have this type of vulnerability. Essentially any relational database management system with user-input options can fall prey to an SQL injection without taking secure coding.

How To Avoid SQL Injection Attacks

via Getty Images

Before we move onto how to avoid SQL Injection Attacks, it’s important to understand exactly what they are and how they work.

Nearly every website, program, app and bit of software that you use has a database or two that is absolutely essential to the whole thing. Search engines are a perfect example of such a database. Under normal circumstances, you enter the terms you wish to search the database for, or enter the data that you want to be saved. No problem.

However, in SQL injection attacks, the field is used to enter a malicious payload.

Here’s an example of code that would be used to login to a website:

# Define POST variables
uname = request.POST['username'] 
passwd = request.POST['password']

# SQL query vulnerable to SQLi sql = “SELECT id FROM users WHERE username=’” + uname + “’ AND password=’” + passwd + “’”
# Execute the SQL statement
database.execute(sql)

Everything here is fairly normal. The user would enter their username and password into the appropriate fields, the code would check this against the database and if everything matched, then the user would be authenticated and granted access, such as in the below example.

SELECT * FROM Users WHERE username ="John Doe" AND password ="myPass"

In SQL injection attacks, rather than entering a simple string of characters to be checked against the database, the code is simply continued.

Rather than entering John Doe into the username field and myPass into the password field, you could enter this instead:

Username:

” or “”=”

Password:

” or “”=”

Which would be read by the database as:

SELECT * FROM Users WHERE username ="" or ""="" AND password ="" or ""=""

Since this is a perfectly valid piece of code for our database, it will simply return ALL entries from Users, as the statement ” or “”=” is always true.

So how can you avoid something like this?

The easiest way is to use prepared statements with parameterized queries, which will allow the user entry to be treated as a string rather than as executable code, regardless of what is typed.

Here’s how this could look in PHP:

$stmt = $dbh->prepare("INSERT INTO Customers (CustomerName,Address,City) 
VALUES (:nam, :add, :cit)");
$stmt->bindParam(':nam', $txtNam);
$stmt->bindParam(':add', $txtAdd);
$stmt->bindParam(':cit', $txtCit);
$stmt->execute();

There are many other ways to prevent SQL injection attacks, but by always building parameterized queries into the code, you’re going to be much more secure.

Continue Reading
Advertisement
1 Comment

1 Comment

  1. Pingback: Help my website has been hacked! >_prevention methods - Hack Ware News

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

HACKING NEWS

How to guide: Check if your Facebook Account has been hacked?

How-to-guide-Check-if-your-Facebook-Account-has-been-hacked

How to guide: Check if your Facebook Account has been hacked?

At the end of September, it was revealed that a Facebook security flaw allowed the access tokens of over 50 Million accounts to be stolen. Access tokens allow users to stay signed in on devices, rather than signing in every time they interact with a Facebook app. On Friday 12 October, after weeks of investigation, Facebook reported that the actual number of accounts affected was 30 million, not 50.

 

The investigation into how this was made possible, and the extent of the data stolen is still ongoing, but Facebook have said there is no need for users to log out or change their password. Facebook forced 90 million users to log out when the breach was discovered.

 

Users can use this page to check if they were one of the accounts affected in the incident, as well as read any recent findings from the investigation. When you visit page, if you are not one of the affected users it will tell you this in a statement towards the bottom of the page, and there is no further action required from you other than remaining security conscious when it comes to passwords and such. You will also see a message saying your account hasn’t been compromised if you are one of the one million users to who their tokens stolen but information remained safe.

 

If you fall into the other 29 million users camp, then you will see one of two messages, depending on the level of your information that was stolen. Fifteen million users had their name, email addresses and phone numbers compromised by hackers. While this is serious enough itself, the other 14 million have a more serious data breach problem.

 

The other 14 million have had the above information stolen, as well as their username, date of birth, devices you use, gender, language settings and possibly more data such as religious and political views. It’s also possible that they accessed your 10 most recent locations and 15 most recent searches, giving a detailed window into your online presence.

 

There is currently no evidence that hackers used the vulnerability to attack third-party apps and services to gather more information, which was technically possible.  Facebook also continues to report that no passwords of credit card information has been compromised. We are yet to see the full fallout from the breach, but there is also evidence that Facebook logins are being sold on the dark web.

 

While that data is now out there in the hands of attackers, Facebook has used their support page to offer some advice on avoiding phishing schemes. This is a good move from Facebook, but it doesn’t make up for the grievous level of the data breach and the users it has left vulnerable to tailored phishing attacks now their data is out there.

Photo by Glen Carrie on Unsplash

Continue Reading

HOW TO

How to Secure Your Linux Server

How to Secure Your Linux Server

How to Secure Your Linux Server

It’s important for anyone running a Linux server, or any type of server for that matter, secure. Especially if it communicates with the outside world. Servers are like your houses in the digital realm. They have to be kept secure from intruders. So you have a Linux server, here’s how to secure it.

  • Keep Your Server Clean and Lean

In other words, keep it simple, but secure. Install the apps and run only the services that you need. Additional apps, introduce vulnerabilities as well as unpatched services that can be exploited by external malicious actors. Keeping the server clean and lean also speeds up its performance. Also, depending on the Linux distro, a number of extra services will be run by default. Keep an eye out for those services. Check if they’re really important and if they are, make sure they’re updated.

A simple netstat –npl command in the terminal will show you all the running services and the ports they use. That’s another thing. These services might be using some ports you want to keep closed. Disable unwanted services with the following command.

Systemctl disable service_name

 

  • Do not Log in as Root

It’s no secret that logging in as Root user gives you unrestricted access to everything in your Linux setup. And for many Linux users, it’s the easiest way to use Linux which is why most newbies log in as Root. Malicious attackers know this too. When users log in as Root, any running apps and services with vulnerabilities also give attackers unlimited access to everything else. The best practice for Linux users, is to create a user with enough sudo access to perform most tasks and only switch to Root when needed.

In Ubuntu for example, you can add a new user with sudo powers by typing in the following at the terminal:

adduser usercansudo

qpasswd –a usercansudo sudo

Afterwards, log out of the system and login as the new user then disable the Root user by editing the sshd_conf file.

Nano /etc/ssh/sshd_conf

Look for this commented item: #PermitRootLogin no

Remove the comment, save the file and restart the ssh service using the following command:

systemctl restart sshd

 

  • Keep the Server to Yourself and others you Trust

Restrict access to your server to just you and others you implicitly trust. In the previous item, create as many users as you can with level access and disable root. The fewer the better though.

  • Port Change

When logging in remotely, the default port for ssh is 22 which is what most people, including attackers would do to get into a Linux server. This port can be changed and by changing this port, eavesdroppers, attackers and bots will be left guessing how to log in to your system. It’s simple but effective. To change the ssh port, we go back to the sshd_conf file. You can issue the following commands:

sudo nano /etc/ssh/sshd_conf

 

Find the commented port line:

#Port 22

 

Uncomment it and change the port number to something else. Feel free to change 22 to something between 1024 and 32,767 but make sure that no other service uses your chosen number. Then save the file. Restart the ssh service.

systemctl restart sshd

 

You can check  if it works by logging in through ssh with this command:

ssh -p{port_number}@server_IP

Example:

ssh –p1027 192.168.10.11

  • Always Keep Your Server Patched and Updated

You’ve probably read plenty of articles regarding vulnerabilities that no basic user could probably think of but continuously explored by determined hackers out for a quick buck. No server is secure, not even Linux and the best defense for this, apart from a good firewall and anti-malware programs, is to keep your operating system and its packages updated. Always be on the lookout for core or kernel updates.

 

[stackCommerce layout=”2″ count=”5″ sort=”best_sellers”][/stackCommerce]

Continue Reading

HOW TO

How To Become an Ethical Hacker – Beginners Guide

How To Become an Ethical Hacker - Beginners Guide- hackwarenewscom

How To Become an Ethical Hacker – Beginners Guide. I’m sure you read stories about ethical hacking, but not knowing what that means?

Our article will cover  few points for people with no experience in cybersecurity or have limited experience.

We receive many emails asking on how to become ethical hacker. Some of more frequent questions “where should I start?”. We will try to answer these questions and give you a more technical details on how to start a career in cybersecurity as a beginner and how to gain more expertise in the domain.

Remember if your goal is to learn hacking for the reason of hacking into your friend’s Facebook account or email, it will not work for you. But if you decided to learn hacking because of your passion for technology and willingness to be an expert in computer systems, things should workout for you!

Career in cybersecurity is more like saying career in Banking. There will be so many niches within the industry from auditing, pentesting, social engineering, digital foresnics, malware / software detecting, etc. You many choose any of the above, however in this article we will cover generic skills that you need before starting your career.

If your background doesn’t bring any experience to the table, don’t worry, we all been there. Nobody has all the necessary skill from beginning. So our advice in your case is to learn absolute fundamentals.

 

  • What is hacking?

Hacking is determining weakness and vulnerabilities of systems and attain access to it.

Ethical hacker have an official and legitimate permission to do a security assessment of a system, but hacker is doing this unauthorized.

Here are some type of hackers for your intro:

Hacktivist – those who hack due to some ideas and to make a statement.

Script kiddie –  they usually use pre-build tools and have no technical skills.

Grey hat  – they reveal the weakens to the company after they get unauthorized access.

Black hat – get unauthorized access

White hat – ethical hacker, they document everything they do and reveal the weaknesses & vulnerabilities to the company.

 

  • What skills required for ethical hacker

– Programming skills

– Fundamentals of Networking

– Operating System

– Get to know as many technology as you can put your hands on

 

  • What to code in ?

To answer this question, one have to consider on what platform you will be working on.

– Web applications: PHP, ASP , JPS

– Mobile apps : Swift/Objective-C, Java( Android) ,

Software [desktop] : C#, C++, Objective-C

It is necessary to learn the fundamentals of programming, like data types, the variable manipulation at the OS level to the use of functions, etc. Here are some tips to take in consideration:

  1. Try to understand the OS level operations on the language you are learning or alternatively learn the assembly language.
  2. Keep your self motivated in your learning path and remember to achieve results takes time.

 

  • Here are resources that will help to learn from scratch
  1. Breaking into Information Security: Learning the Ropes 101
  2. Web Hacking 101

 

Continue Reading
Advertisement

Trending