• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cross Site request Forgery

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Found security vulnerability when application is scanned .
While scanning the application, they are passing diff values for TRANS_CD, due to these invalid values , system thorwing exception , how can we restrict this ?

16 Apr 2013 16:58:58,105 [SocketListener0-7] ERROR com.xelus.solos.trans.TransRunner - Object Not In Db Exception
com.xelus.solos.persistent.ObjectNotInDbException: TransactionMap could not be found in the database with key of TRANS_CD = [DISPLAY_1C_SELECTION' OR]
at com.xelus.solos.persistent.TransactionMap.loadByTransCd(Unknown Source)


16 Apr 2013 16:59:09,970 [SocketListener0-7] ERROR com.xelus.solos.trans.TransRunner - Object Not In Db Exception
com.xelus.solos.persistent.ObjectNotInDbException: TransactionMap could not be found in the database with key of TRANS_CD = [DISPLAY_1C_SELECTION' AND 5=5 OR 's'='0]
at com.xelus.solos.persistent.TransactionMap.loadByTransCd(Unknown Source)
at com.xelus.solos.trans.TransRunner.execute(Unknown Source)


Code:

PreparedStatement pstmt = con.prepareStatement(
"SELECT " + Consts.FIELD_TRANS_CD + ", "
+ Consts.FIELD_TRANS_GOTO_CD + ", "
+ Consts.FIELD_TRANS_CLASS_NM + ", "
+ Consts.FIELD_TRANS_METHOD_NM + ", "
+ Consts.FIELD_UPDATE_STAMP + " "
+ "FROM " + Consts.TABLE_TRANS + " "
+ "WHERE " + Consts.FIELD_TRANS_CD + "= ? ");

pstmt.setString(1, transCd);


ResultSet rs = pstmt.executeQuery();

if (rs.next()) {
_isPersistent = true;
_transCd = rs.getString(1);
_transGotoCd = rs.getString(2);
_transClassNm = rs.getString(3);
_transMethodNm = rs.getString(4);
_updateStamp = rs.getString(5);
}
else {
clear();
rs.close();
pstmt.close();
connectionManager.freeConnection(con);

throw new ObjectNotInDbException("TransactionMap",
"TRANS_CD = [" + transCd + "]");
}


Please help me how to resolve this issue.

 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's not cross site request forgery. It looks like they were trying to do SQL Injection. And failed since that code protects against SQL Injection. If you don't want to throw ane xception on error, you can catch the exception. It is a good idea to not be showing the user a stack trace. But it's not cross site request forgery.
 
lakshmi gullapudi
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, it looks like SQL injection.

In many sites , its mentioned use prepared statements to avoid SQL injections.

in my code we are using prepared statement , but still this vulnerability occuring in scan .

How can i restrict this or how can i prevent this SQL injection?

Please help me.
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually it is an attempted SQL injection attack. You obviously cannot prevent such attempts, you can only make sure they fail - which they did. "Preventing SQL injection" usually means exactly that - making sure the attacker won't gain unauthorized access using SQL injection. If you weren't using prepared statements (nor had escaped the inputs properly, but it is a lot of unnecessary work), the attacker might perhaps execute some unauthorized statements in the database.

The SQL injection attacks is based on entering invalid inputs to the application. Obviously that causes errors in the application. You can handle these errors one way or another - you might, for example, check that the user input corresponds to an expected format, but sometimes that could be hard. I don't think relying on an exception being thrown is a bad solution, assuming you don't show the exception details to the end user.
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

lakshmi gullapudi wrote:in my code we are using prepared statement , but still this vulnerability occuring in scan .


What exactly is it saying about the vulnerability in the scan? Because I think it is wrong.
 
them good ole boys were drinking whiskey and rye singin' this'll be the day that I die. Drink tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic