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. Other Discussions
  3. The Weird and The Wonderful
  4. Give a right username and a right password and you're in...

Give a right username and a right password and you're in...

Scheduled Pinned Locked Moved The Weird and The Wonderful
databasesysadminquestion
13 Posts 8 Posters 3 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.
  • Y yiangos

    I was asked to make small amendments to an ages old ASP Classic website. So I tried to log into the "administration" area, didn't know what username/password to use, and opened up the code to see where in the database (MSAccess) I should look for valid credentials... Behold (some details left out/altered to protect involved parties):

    Dim msg
    msg=""
    Dim sql
    sql="SELECT * FROM USERS WHERE (usr= '" + username +"')"

    Dim rs
    Set rs = Server.CreateObject("ADODB.Recordset")
    rs.ActiveConnection = dbconnSTRING
    rs.Source = sql
    rs.CursorType = 0
    rs.CursorLocation = 2
    rs.Open()

    if rs.Eof And rs.Bof then
    msg="Invalid username"
    end if
    sql="SELECT * FROM USERS WHERE (pswd= '"+ password +"')"
    rs.Close()
    rs.Open(sql)
    if rs.Eof And rs.Bof then
    if msg="Invalid username" then
    msg="Invalid username and password"
    else
    msg="Invalid password"
    end if
    end if

    So basically if I know your username and I have my own account, I can use your username and my password and log in as you... Nice eh?

    Φευ! Εδόμεθα υπό ρηννοσχήμων λύκων! (Alas! We're devoured by lamb-guised wolves!)

    T Offline
    T Offline
    tgrt
    wrote on last edited by
    #2

    wow

    1 Reply Last reply
    0
    • Y yiangos

      I was asked to make small amendments to an ages old ASP Classic website. So I tried to log into the "administration" area, didn't know what username/password to use, and opened up the code to see where in the database (MSAccess) I should look for valid credentials... Behold (some details left out/altered to protect involved parties):

      Dim msg
      msg=""
      Dim sql
      sql="SELECT * FROM USERS WHERE (usr= '" + username +"')"

      Dim rs
      Set rs = Server.CreateObject("ADODB.Recordset")
      rs.ActiveConnection = dbconnSTRING
      rs.Source = sql
      rs.CursorType = 0
      rs.CursorLocation = 2
      rs.Open()

      if rs.Eof And rs.Bof then
      msg="Invalid username"
      end if
      sql="SELECT * FROM USERS WHERE (pswd= '"+ password +"')"
      rs.Close()
      rs.Open(sql)
      if rs.Eof And rs.Bof then
      if msg="Invalid username" then
      msg="Invalid username and password"
      else
      msg="Invalid password"
      end if
      end if

      So basically if I know your username and I have my own account, I can use your username and my password and log in as you... Nice eh?

      Φευ! Εδόμεθα υπό ρηννοσχήμων λύκων! (Alas! We're devoured by lamb-guised wolves!)

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #3

      :thumbsup: A thing of beauty. Thanks for immortalizing it here. P.S. I'll also take a moment to point out that such a validation routine should never indicate what went wrong, only that it failed. Telling a potential baddy that the user name doesn't exist makes his job easier -- he's simply stop trying that username and move on to the next without trying any more passwords.

      B 1 Reply Last reply
      0
      • Y yiangos

        I was asked to make small amendments to an ages old ASP Classic website. So I tried to log into the "administration" area, didn't know what username/password to use, and opened up the code to see where in the database (MSAccess) I should look for valid credentials... Behold (some details left out/altered to protect involved parties):

        Dim msg
        msg=""
        Dim sql
        sql="SELECT * FROM USERS WHERE (usr= '" + username +"')"

        Dim rs
        Set rs = Server.CreateObject("ADODB.Recordset")
        rs.ActiveConnection = dbconnSTRING
        rs.Source = sql
        rs.CursorType = 0
        rs.CursorLocation = 2
        rs.Open()

        if rs.Eof And rs.Bof then
        msg="Invalid username"
        end if
        sql="SELECT * FROM USERS WHERE (pswd= '"+ password +"')"
        rs.Close()
        rs.Open(sql)
        if rs.Eof And rs.Bof then
        if msg="Invalid username" then
        msg="Invalid username and password"
        else
        msg="Invalid password"
        end if
        end if

        So basically if I know your username and I have my own account, I can use your username and my password and log in as you... Nice eh?

        Φευ! Εδόμεθα υπό ρηννοσχήμων λύκων! (Alas! We're devoured by lamb-guised wolves!)

        J Offline
        J Offline
        JMK NI
        wrote on last edited by
        #4

        Airtight :cool:

        1 Reply Last reply
        0
        • Y yiangos

          I was asked to make small amendments to an ages old ASP Classic website. So I tried to log into the "administration" area, didn't know what username/password to use, and opened up the code to see where in the database (MSAccess) I should look for valid credentials... Behold (some details left out/altered to protect involved parties):

          Dim msg
          msg=""
          Dim sql
          sql="SELECT * FROM USERS WHERE (usr= '" + username +"')"

          Dim rs
          Set rs = Server.CreateObject("ADODB.Recordset")
          rs.ActiveConnection = dbconnSTRING
          rs.Source = sql
          rs.CursorType = 0
          rs.CursorLocation = 2
          rs.Open()

          if rs.Eof And rs.Bof then
          msg="Invalid username"
          end if
          sql="SELECT * FROM USERS WHERE (pswd= '"+ password +"')"
          rs.Close()
          rs.Open(sql)
          if rs.Eof And rs.Bof then
          if msg="Invalid username" then
          msg="Invalid username and password"
          else
          msg="Invalid password"
          end if
          end if

          So basically if I know your username and I have my own account, I can use your username and my password and log in as you... Nice eh?

          Φευ! Εδόμεθα υπό ρηννοσχήμων λύκων! (Alas! We're devoured by lamb-guised wolves!)

          I Offline
          I Offline
          Ian Shlasko
          wrote on last edited by
          #5

          Bah, I don't need a valid username OR a valid password...

          Username: 'or''='
          Password: 'or''='

          I know, I know... I'm supposed to drop/wipe the table, but that's just mean.

          Proud to have finally moved to the A-Ark. Which one are you in?
          Author of the Guardians Saga (Sci-Fi/Fantasy novels)

          Y 1 Reply Last reply
          0
          • Y yiangos

            I was asked to make small amendments to an ages old ASP Classic website. So I tried to log into the "administration" area, didn't know what username/password to use, and opened up the code to see where in the database (MSAccess) I should look for valid credentials... Behold (some details left out/altered to protect involved parties):

            Dim msg
            msg=""
            Dim sql
            sql="SELECT * FROM USERS WHERE (usr= '" + username +"')"

            Dim rs
            Set rs = Server.CreateObject("ADODB.Recordset")
            rs.ActiveConnection = dbconnSTRING
            rs.Source = sql
            rs.CursorType = 0
            rs.CursorLocation = 2
            rs.Open()

            if rs.Eof And rs.Bof then
            msg="Invalid username"
            end if
            sql="SELECT * FROM USERS WHERE (pswd= '"+ password +"')"
            rs.Close()
            rs.Open(sql)
            if rs.Eof And rs.Bof then
            if msg="Invalid username" then
            msg="Invalid username and password"
            else
            msg="Invalid password"
            end if
            end if

            So basically if I know your username and I have my own account, I can use your username and my password and log in as you... Nice eh?

            Φευ! Εδόμεθα υπό ρηννοσχήμων λύκων! (Alas! We're devoured by lamb-guised wolves!)

            D Offline
            D Offline
            dexterama
            wrote on last edited by
            #6

            I think the lesson you can derive from this is to teach the developer who wrote this what the AND keyword means in SQL syntax.

            Y 1 Reply Last reply
            0
            • I Ian Shlasko

              Bah, I don't need a valid username OR a valid password...

              Username: 'or''='
              Password: 'or''='

              I know, I know... I'm supposed to drop/wipe the table, but that's just mean.

              Proud to have finally moved to the A-Ark. Which one are you in?
              Author of the Guardians Saga (Sci-Fi/Fantasy novels)

              Y Offline
              Y Offline
              yiangos
              wrote on last edited by
              #7

              Nah, username and password were sanitized earlier in the code. Surprisingly, the sanitization routine is pretty solid (probably copy-pasted from elsewhere though, seems quite out-of-place in terms of coding style).

              Φευ! Εδόμεθα υπό ρηννοσχήμων λύκων! (Alas! We're devoured by lamb-guised wolves!)

              1 Reply Last reply
              0
              • D dexterama

                I think the lesson you can derive from this is to teach the developer who wrote this what the AND keyword means in SQL syntax.

                Y Offline
                Y Offline
                yiangos
                wrote on last edited by
                #8

                Actually, the person who originally wrote this little gem currently has something close to 25 years of active development under their belt, with extensive SQL work as well. I've seen other samples of their work, written about the same time as this, and they are REALLY better than this. So this leads me to think that they were smoking something REALLY good when they wrote this.

                Φευ! Εδόμεθα υπό ρηννοσχήμων λύκων! (Alas! We're devoured by lamb-guised wolves!)

                P 1 Reply Last reply
                0
                • Y yiangos

                  Actually, the person who originally wrote this little gem currently has something close to 25 years of active development under their belt, with extensive SQL work as well. I've seen other samples of their work, written about the same time as this, and they are REALLY better than this. So this leads me to think that they were smoking something REALLY good when they wrote this.

                  Φευ! Εδόμεθα υπό ρηννοσχήμων λύκων! (Alas! We're devoured by lamb-guised wolves!)

                  P Offline
                  P Offline
                  PIEBALDconsult
                  wrote on last edited by
                  #9

                  Or as a back door?

                  Y 1 Reply Last reply
                  0
                  • P PIEBALDconsult

                    Or as a back door?

                    Y Offline
                    Y Offline
                    yiangos
                    wrote on last edited by
                    #10

                    Yeah, that might be the case:suss:. But not anymore :cool:

                    Φευ! Εδόμεθα υπό ρηννοσχήμων λύκων! (Alas! We're devoured by lamb-guised wolves!)

                    1 Reply Last reply
                    0
                    • Y yiangos

                      I was asked to make small amendments to an ages old ASP Classic website. So I tried to log into the "administration" area, didn't know what username/password to use, and opened up the code to see where in the database (MSAccess) I should look for valid credentials... Behold (some details left out/altered to protect involved parties):

                      Dim msg
                      msg=""
                      Dim sql
                      sql="SELECT * FROM USERS WHERE (usr= '" + username +"')"

                      Dim rs
                      Set rs = Server.CreateObject("ADODB.Recordset")
                      rs.ActiveConnection = dbconnSTRING
                      rs.Source = sql
                      rs.CursorType = 0
                      rs.CursorLocation = 2
                      rs.Open()

                      if rs.Eof And rs.Bof then
                      msg="Invalid username"
                      end if
                      sql="SELECT * FROM USERS WHERE (pswd= '"+ password +"')"
                      rs.Close()
                      rs.Open(sql)
                      if rs.Eof And rs.Bof then
                      if msg="Invalid username" then
                      msg="Invalid username and password"
                      else
                      msg="Invalid password"
                      end if
                      end if

                      So basically if I know your username and I have my own account, I can use your username and my password and log in as you... Nice eh?

                      Φευ! Εδόμεθα υπό ρηννοσχήμων λύκων! (Alas! We're devoured by lamb-guised wolves!)

                      M Offline
                      M Offline
                      Marc Koutzarov
                      wrote on last edited by
                      #11

                      Code from the time that Sex was safe and flying dangerous ;P

                      Y 1 Reply Last reply
                      0
                      • M Marc Koutzarov

                        Code from the time that Sex was safe and flying dangerous ;P

                        Y Offline
                        Y Offline
                        yiangos
                        wrote on last edited by
                        #12

                        Well, flying is still somewhat dangerous...

                        Φευ! Εδόμεθα υπό ρηννοσχήμων λύκων! (Alas! We're devoured by lamb-guised wolves!)

                        1 Reply Last reply
                        0
                        • P PIEBALDconsult

                          :thumbsup: A thing of beauty. Thanks for immortalizing it here. P.S. I'll also take a moment to point out that such a validation routine should never indicate what went wrong, only that it failed. Telling a potential baddy that the user name doesn't exist makes his job easier -- he's simply stop trying that username and move on to the next without trying any more passwords.

                          B Offline
                          B Offline
                          BobJanova
                          wrote on last edited by
                          #13

                          I'm never sure about that one. Yes, it has a marginal effect on security, but it has a big effect on user annoyance, and I think the trade-off is worth it in most cases to let a user know that they mistyped their username.

                          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