sql-injection

Do I need to use (int)$id before I use $id in bindValue in Php PDO

[亡魂溺海] 提交于 2019-12-01 13:54:39
I just started using Php Data Objects and one thing I'm not sure about is do I have to validate that some variable is an integer before using it in the query. For example, like this: $id = (int)$_POST['id']; // is this required $query = $pdo->prepare("SELECT * FROM `articles` WHERE `id` = ?"); $query->bindValue(1, $id); $query->execute(); No it's not required for two reasons: You're letting PDO know that you are going to query the database for a column ID. PDO isn't going to parse anything in $_POST['id'] . The second value of bindValue is automatically casted to a string (or of any type you

Is an SQL injection actually possible by adding a second query?

天大地大妈咪最大 提交于 2019-12-01 13:50:28
There's a lot of warnings about SQL injections here on SO, but no one I've found doesn't really answer, how does it happen? In this question, I'm assuming it's MySQL and PHP. The basic mysql_ doesn't accept a second query inside a query, right? So, basically, this $unsafe = "');DROP TABLE table;--"; mysqli_query($con,"INSERT INTO table (Column) VALUES ('$unsafe'"); doesn't actually do anything harmful? Correct me on this. I've no experience working with mysqli_ , so I'll skip to PDO, and "Prepared statements". When I started working with PDO, I had a lack of information on it, and basically

Selecting data from mySQL using the ID in URL

梦想的初衷 提交于 2019-12-01 13:48:32
I have a table that has the columns GroupID | GroupName | GroupDesc | Overs | ----------------------------------------- 1 | Test Group|Description| Yes | I have a page called list.php and it currently creates the URL for each row in the DB in the groups table(above). The code is not the prettiest but I think it works this is he code list.php <?php $result = mysql_query("SELECT * FROM groups"); while($row = mysql_fetch_array($result)) { echo "<div class=\"divider\">"; echo "<a href=\"group.php?id="; echo $row['GroupID']; echo "\">"; echo $row['GroupName']; echo "</a>"; echo "<br><br>"; echo

SQL injection with php filtering

让人想犯罪 __ 提交于 2019-12-01 12:12:07
问题 I have to inject a login form for exercise about a computer security course .... I have passed the first level using the simple ' like 1=1-- in the password field, but now in the second level i have to inject again the same login form with the same source code except for the fact that user and pwd are being controlled by a function called lvl2_filter() which i think is part of filters.php and do not accept "=" and "OR" How can i do it ??? both username and password field cannot be empty

Selecting data from mySQL using the ID in URL

怎甘沉沦 提交于 2019-12-01 11:18:31
问题 I have a table that has the columns GroupID | GroupName | GroupDesc | Overs | ----------------------------------------- 1 | Test Group|Description| Yes | I have a page called list.php and it currently creates the URL for each row in the DB in the groups table(above). The code is not the prettiest but I think it works this is he code list.php <?php $result = mysql_query("SELECT * FROM groups"); while($row = mysql_fetch_array($result)) { echo "<div class=\"divider\">"; echo "<a href=\"group.php

How to cleanse a string to avoid SQL Injection and the most common types of attack? (in PHP)

試著忘記壹切 提交于 2019-12-01 10:47:09
Is there a way to, in as little code as possible, to filter a string for both SQL injection and the most common forms of attack? In my scripts I'm using the following, I would like to know whether it's reasonably safe and whether someone else has a suggestion: $cleanName = htmlspecialchars(addslashes($dirtyName)); See how I filtered it both for html chars and for quotes and double-quotes. NOTE: I'm using addslashes() rather than mysql_real_escape_string() because I don't want to hardcode the DB I'm using into my code. Is this ok? Thanks in advance Probably not... you need to escape your raw

SQL injection on Classic ASP pages with parameterized queries: text fields

杀马特。学长 韩版系。学妹 提交于 2019-12-01 09:16:31
I've parameterized my queries in my Classic ASP app, but am unsure whether I need to sanitize or scrub free text fields or if the parameterization is sufficient to prevent injection. Not all sql stored procs are injection safe http://palisade.plynt.com/issues/2006Jun/injection-stored-procedures/ If you use parametrized queries, you're safe against SQL injection attacks. But not for XSS attacks ; some user could to insert HTML content (think about <script> , <object> tags) into your database and, at some page, another user get that potentially malicious code executed. 来源: https://stackoverflow

How to cleanse a string to avoid SQL Injection and the most common types of attack? (in PHP)

会有一股神秘感。 提交于 2019-12-01 08:35:51
问题 Is there a way to, in as little code as possible, to filter a string for both SQL injection and the most common forms of attack? In my scripts I'm using the following, I would like to know whether it's reasonably safe and whether someone else has a suggestion: $cleanName = htmlspecialchars(addslashes($dirtyName)); See how I filtered it both for html chars and for quotes and double-quotes. NOTE: I'm using addslashes() rather than mysql_real_escape_string() because I don't want to hardcode the

Secure against SQL Injection - PDO, mysqli [duplicate]

筅森魡賤 提交于 2019-12-01 08:26:39
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Best way to prevent SQL Injection in PHP I just found that my website is vunerable. Since it's connected to a DB and have functions like: Register, Change Password, Notices, etc... and SUPOSING it's fully vulnerable. What should I look for into the code in order to start making it safe? I mean, I did some researches and everywhere, everyone says different things about security. "Use PDO." "Use mysql_real_escape

With stored procedures, is cfSqlType necessary?

牧云@^-^@ 提交于 2019-12-01 08:23:40
To protect against sql injection, I read in the introduction to ColdFusion that we are to use the cfqueryparam tag. But when using stored procedures, I am passing my variables to corresponding variable declarations in SQL Server: DROP PROC Usr.[Save] GO CREATE PROC Usr.[Save] (@UsrID Int ,@UsrName varchar(max) ) AS UPDATE Usr SET UsrName = @UsrName WHERE UsrID=@UsrID exec Usr.[get] @UsrID Q: Is there any value in including cfSqlType when I call a stored procedure? Here's how I'm currently doing it in Lucee: storedproc procedure='Usr.[Save]' { procparam value=Val(form.UsrID); procparam value