Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. SQL Injection License Plate

SQL Injection License Plate

Scheduled Pinned Locked Moved The Lounge
databasecomquestion
18 Posts 11 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L LucianPopescu

    I'm just wondering, would that [^] really work ?? lol

    K Offline
    K Offline
    kevinnicol
    wrote on last edited by
    #3

    Nice! Tough to say if it would work without seeing any code, but from the code on the license plate, my instinct says no.

    1 Reply Last reply
    0
    • L LucianPopescu

      I'm just wondering, would that [^] really work ?? lol

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #4

      No it wont work, he spelt 'POLICE' wrong... :doh:

      xacc.ide
      IronScheme - 1.0 RC 1 - out now!
      ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

      1 Reply Last reply
      0
      • L LucianPopescu

        I'm just wondering, would that [^] really work ?? lol

        L Offline
        L Offline
        LucianPopescu
        wrote on last edited by
        #5

        I mean, the Traffic Cameras really work this way ? they read/recognize the license number and automatically insert into database ??

        OriginalGriffO L 2 Replies Last reply
        0
        • L LucianPopescu

          I'm just wondering, would that [^] really work ?? lol

          H Offline
          H Offline
          HimanshuJoshi
          wrote on last edited by
          #6

          :laugh: :laugh: :laugh:

          "I'm willing to admit that I may not always be right, but I am never wrong." - Samuel Goldwyn

          1 Reply Last reply
          0
          • L LucianPopescu

            I mean, the Traffic Cameras really work this way ? they read/recognize the license number and automatically insert into database ??

            OriginalGriffO Offline
            OriginalGriffO Offline
            OriginalGriff
            wrote on last edited by
            #7

            An SQL Injection attack does not require a database insert - a SELECT ... FROM query will do. Since the ";" is SQL for end-of-statement, the code after it is considered to be a new instruction and executed separately. So "SELECT * FROM tab WHERE number = 123;DROP TABLES tab" would perform two separate operations: Query the table, then delete it. This is why parameterised queries are so important!

            You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
            "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

            L E 2 Replies Last reply
            0
            • L LucianPopescu

              I mean, the Traffic Cameras really work this way ? they read/recognize the license number and automatically insert into database ??

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #8

              Perhaps not the camera itself, but the image is at some point processed with some kind of OCR and then probably the result is inserted into a database.

              A while ago he asked me what he should have printed on my business cards. I said 'Wizard'. I read books which nobody else understand. Then I do something which nobody understands. After that the computer does something which nobody understands. When asked, I say things about the results which nobody understand. But everybody expects miracles from me on a regular basis. Looks to me like the classical definition of a wizard.

              1 Reply Last reply
              0
              • OriginalGriffO OriginalGriff

                An SQL Injection attack does not require a database insert - a SELECT ... FROM query will do. Since the ";" is SQL for end-of-statement, the code after it is considered to be a new instruction and executed separately. So "SELECT * FROM tab WHERE number = 123;DROP TABLES tab" would perform two separate operations: Query the table, then delete it. This is why parameterised queries are so important!

                You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy

                L Offline
                L Offline
                LucianPopescu
                wrote on last edited by
                #9

                OriginalGriff wrote:

                This is why parameterised queries are so important!

                By parameterized, you mean stored procedures or what ?

                OriginalGriffO 1 Reply Last reply
                0
                • L LucianPopescu

                  OriginalGriff wrote:

                  This is why parameterised queries are so important!

                  By parameterized, you mean stored procedures or what ?

                  OriginalGriffO Offline
                  OriginalGriffO Offline
                  OriginalGriff
                  wrote on last edited by
                  #10

                  pLucian wrote:

                  By parameterized, you mean stored procedures or what ?

                  No! :laugh: Instead of the SQL

                  SqlCommand cmd = SqlCommand("SELECT * FROM tab WHERE name = " + tbName.Text);

                  Use

                  SqlCommand cmd = SqlCommand("SELECT * FROM tab WHERE name = @NAME");
                  cmd.AddWithValue("@NAME", tbName.Text);

                  This way the content of tbName can be any characters without it being accepted as a new SQL command. (Yes, yes, I know - "don't use SELECT * FROM" because it... yada yada yada! Don't be so picky!)

                  You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy

                  "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                  "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                  L C 2 Replies Last reply
                  0
                  • L LucianPopescu

                    I'm just wondering, would that [^] really work ?? lol

                    D Offline
                    D Offline
                    dan sh
                    wrote on last edited by
                    #11

                    I don't think this would harm the database. Do they store the entire image or extract just the number and then store it? Even if they store the number, there has to be some sort of encryption happening before insert.

                    1 Reply Last reply
                    0
                    • OriginalGriffO OriginalGriff

                      pLucian wrote:

                      By parameterized, you mean stored procedures or what ?

                      No! :laugh: Instead of the SQL

                      SqlCommand cmd = SqlCommand("SELECT * FROM tab WHERE name = " + tbName.Text);

                      Use

                      SqlCommand cmd = SqlCommand("SELECT * FROM tab WHERE name = @NAME");
                      cmd.AddWithValue("@NAME", tbName.Text);

                      This way the content of tbName can be any characters without it being accepted as a new SQL command. (Yes, yes, I know - "don't use SELECT * FROM" because it... yada yada yada! Don't be so picky!)

                      You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy

                      L Offline
                      L Offline
                      LucianPopescu
                      wrote on last edited by
                      #12

                      very nice, i didn't knew about this ;) good to know.

                      1 Reply Last reply
                      0
                      • OriginalGriffO OriginalGriff

                        pLucian wrote:

                        By parameterized, you mean stored procedures or what ?

                        No! :laugh: Instead of the SQL

                        SqlCommand cmd = SqlCommand("SELECT * FROM tab WHERE name = " + tbName.Text);

                        Use

                        SqlCommand cmd = SqlCommand("SELECT * FROM tab WHERE name = @NAME");
                        cmd.AddWithValue("@NAME", tbName.Text);

                        This way the content of tbName can be any characters without it being accepted as a new SQL command. (Yes, yes, I know - "don't use SELECT * FROM" because it... yada yada yada! Don't be so picky!)

                        You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy

                        C Offline
                        C Offline
                        Corporal Agarn
                        wrote on last edited by
                        #13

                        OriginalGriff wrote:

                        (Yes, yes, I know - "don't use SELECT * FROM" because it... yada yada yada! Don't be so picky!)

                        :laugh: :laugh: :laugh:

                        1 Reply Last reply
                        0
                        • L LucianPopescu

                          I'm just wondering, would that [^] really work ?? lol

                          G Offline
                          G Offline
                          Gareth H
                          wrote on last edited by
                          #14

                          It wouldnt work in the UK, since they pay someone to look through every image and verify that its correct. But it would be nice if it did...

                          Regards, Gareth. (FKA gareth111)

                          1 Reply Last reply
                          0
                          • OriginalGriffO OriginalGriff

                            An SQL Injection attack does not require a database insert - a SELECT ... FROM query will do. Since the ";" is SQL for end-of-statement, the code after it is considered to be a new instruction and executed separately. So "SELECT * FROM tab WHERE number = 123;DROP TABLES tab" would perform two separate operations: Query the table, then delete it. This is why parameterised queries are so important!

                            You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy

                            E Offline
                            E Offline
                            Electron Shepherd
                            wrote on last edited by
                            #15

                            OriginalGriff wrote:

                            This is why parameterised queries are so important!

                            Or just escape out the string. A big limitation with parameterised queries is they are rather tricky to use with "IN" clauses.

                            Server and Network Monitoring

                            A 1 Reply Last reply
                            0
                            • E Electron Shepherd

                              OriginalGriff wrote:

                              This is why parameterised queries are so important!

                              Or just escape out the string. A big limitation with parameterised queries is they are rather tricky to use with "IN" clauses.

                              Server and Network Monitoring

                              A Offline
                              A Offline
                              AspDotNetDev
                              wrote on last edited by
                              #16

                              private SqlDataReader GetSomeStuff(SqlConnection conn, List<string> vals)
                              {

                              // Create query.
                              StringBuilder sb = new StringBuilder();
                              for (int i = 0; i < vals.Count; i++)
                              {
                                  if (i != 0) sb.Append(", ");
                                  sb.Append("@param" + i.ToString());
                              }
                              string query = string.Format("SELECT \* FROM TheTable WHERE TheColumn IN ({0})", sb.ToString());
                              
                              
                              // Add each parameter to command.
                              SqlCommand cmd = new SqlCommand(query, conn);
                              for(int i = 0; i < vals.Count; i++)
                              {
                                  cmd.Parameters.Add(new SqlParameter("param" + i.ToString(), vals\[i\]));
                              }
                              
                              
                              // Execute.
                              return cmd.ExecuteReader();
                              

                              }

                              Now, was that so hard? Though, with SQL Server 2008 (and I think 2005), entire tables can be passed as parameters, which removes the need to dynamically construct the query. The above technique won't work very well with stored procedures though. In cases like that, one can create an intermediate table to bulk insert data into, generate a unique batch ID from that, then pass that ID to the stored procedure so it knows which records in the batch table to use (after which, it can delete those records).

                              [Forum Guidelines]

                              E 1 Reply Last reply
                              0
                              • A AspDotNetDev

                                private SqlDataReader GetSomeStuff(SqlConnection conn, List<string> vals)
                                {

                                // Create query.
                                StringBuilder sb = new StringBuilder();
                                for (int i = 0; i < vals.Count; i++)
                                {
                                    if (i != 0) sb.Append(", ");
                                    sb.Append("@param" + i.ToString());
                                }
                                string query = string.Format("SELECT \* FROM TheTable WHERE TheColumn IN ({0})", sb.ToString());
                                
                                
                                // Add each parameter to command.
                                SqlCommand cmd = new SqlCommand(query, conn);
                                for(int i = 0; i < vals.Count; i++)
                                {
                                    cmd.Parameters.Add(new SqlParameter("param" + i.ToString(), vals\[i\]));
                                }
                                
                                
                                // Execute.
                                return cmd.ExecuteReader();
                                

                                }

                                Now, was that so hard? Though, with SQL Server 2008 (and I think 2005), entire tables can be passed as parameters, which removes the need to dynamically construct the query. The above technique won't work very well with stored procedures though. In cases like that, one can create an intermediate table to bulk insert data into, generate a unique batch ID from that, then pass that ID to the stored procedure so it knows which records in the batch table to use (after which, it can delete those records).

                                [Forum Guidelines]

                                E Offline
                                E Offline
                                Electron Shepherd
                                wrote on last edited by
                                #17

                                aspdotnetdev wrote:

                                Now, was that so hard?

                                Err, yes. You quote a simple example (consider the extra logic to handle the case where there are additional parameters to be added), when all you needed to do was double up any single quotes in each parameter, and put single quotes at either side of it - a very simple string manipulation operation.

                                aspdotnetdev wrote:

                                one can create an intermediate table to bulk insert data into, generate a unique batch ID from that, then pass that ID to the stored procedure

                                Sounds very efficient, easy to debug and highly portable...

                                Server and Network Monitoring

                                A 1 Reply Last reply
                                0
                                • E Electron Shepherd

                                  aspdotnetdev wrote:

                                  Now, was that so hard?

                                  Err, yes. You quote a simple example (consider the extra logic to handle the case where there are additional parameters to be added), when all you needed to do was double up any single quotes in each parameter, and put single quotes at either side of it - a very simple string manipulation operation.

                                  aspdotnetdev wrote:

                                  one can create an intermediate table to bulk insert data into, generate a unique batch ID from that, then pass that ID to the stored procedure

                                  Sounds very efficient, easy to debug and highly portable...

                                  Server and Network Monitoring

                                  A Offline
                                  A Offline
                                  AspDotNetDev
                                  wrote on last edited by
                                  #18

                                  Electron Shepherd wrote:

                                  all you needed to do was double up any single quotes in each parameter

                                  How about for NULL (no quotes, though that wouldn't be much use in the specific case of an IN operator)? And for date times ("3/6/2010" is March 6th or June 3rd, and that doesn't even take into account millisecond precision)? And for numbers (no quoting necessary)? And when C# uses scientific notation to represent numbers but SQL Server does not ("100000000.0" vs "1.0E8")? Or when a different culture processes certain data types (e.g., date times) differently? Not so simple after all, now is it? And I think it wasn't very hard to create a list of strings in the format "@param0, @param1, ..., @paramN". As far as bulk inserts... that is quite efficient. But different strokes for different folks.

                                  [Forum Guidelines]

                                  1 Reply Last reply
                                  0
                                  Reply
                                  • Reply as topic
                                  Log in to reply
                                  • Oldest to Newest
                                  • Newest to Oldest
                                  • Most Votes


                                  • Login

                                  • Don't have an account? Register

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • World
                                  • Users
                                  • Groups