CVE-2015-10026 (published 2023-01-07T13:15Z)

A vulnerability was found in tiredtyrant flairbot. It has been declared as critical. This vulnerability affects unknown code of the file flair.py. The manipulation leads to sql injection. The patch is identified as 5e112b68c6faad1d4699d02c1ebbb7daf48ef8fb. It is recommended to apply a patch to fix this issue. VDB-217618 is the identifier assigned to this vulnerability.

CVSS v3 base score: 9.8, CRITICAL (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H)

Weakness information:
cwe_id: CWE-89
cwe_name: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
description: The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. Without sufficient removal or quoting of SQL syntax in user-controllable inputs, the generated SQL query can cause those inputs to be interpreted as SQL instead of ordinary user data.
extended_description: 
            
            
         
         

Fix information:
repo_url: https://github.com/tiredtyrant/flairbot
commit_details: repo_url: https://github.com/tiredtyrant/flairbot
author: tiredtyrant
author_date: 2015-04-27 20:40:31-04:00
msg: Alteracoes nas queries para evitar sql injection

Signed-off-by: tiredtyrant <tiredtyrant@gmail.com>
repository: repo_url: https://github.com/tiredtyrant/flairbot
repo_name: tiredtyrant/flairbot
description: Bot para gerenciar flair de users no reddit
repo_language: PLpgSQL
owner: tiredtyrant
file_changes: filename: flair.py
change_type: ModificationType.MODIFY
diff: @@ -9,8 +9,8 @@ cursor = con.cursor()
 def dbLookup(msg):
     if len(msg.split(',')) != 2:
         #procura na lista de paises
-        query = 'SELECT id FROM paises WHERE nome == "%s"' % (msg)
-        cursor.execute(query)
+        query = 'SELECT id FROM paises WHERE nome == ?;'
+        cursor.execute(query,(msg,))
         if cursor.fetchone():
             return True
         else:
@@ -19,8 +19,8 @@ def dbLookup(msg):
         cidade = msg.split(',')[0].strip()
         estado = msg.split(',')[1].strip()
         #check cidade pertence ao estado
-        query = 'SELECT estados.id FROM municipios JOIN estados ON municipios.estados_id == estados.id WHERE municipios.nome == "%s" AND estados.uf == "%s";' % (cidade, estado)
-        cursor.execute(query)
+        query = 'SELECT estados.id FROM municipios JOIN estados ON municipios.estados_id == estados.id WHERE municipios.nome == ? AND estados.uf == ?;'
+        cursor.execute(query,(cidade,estado))
         if not cursor.fetchone():
             return False
             
@@ -37,28 +37,31 @@ def main():
         return
     while True:
         time.sleep(0.5)
-        for msg in r.get_unread(limit=None):
-            try:
-                print 'AUTHOR: %s - SUBJECT: %s - BODY: %s' % (msg.author, msg.subject, msg.body)
-            except UnicodeEncodeError:
-                print 'AUTHOR: %s - unprintable chars' % (msg.author)
-            sub = r.get_subreddit('brasil')
-            if msg.subject == 'flair':
-                if dbLookup(msg.body):
-                    estado = 'world' if len(msg.body.split(',')) < 2 else msg.body.split(',')[1].strip()
-                    sub.set_flair(msg.author,msg.body,estado)
-                    r.send_message(msg.author,'flair','Flair configurado.')
-                    print('flair ok')
-                else:
-                    r.send_message(msg.author,'flair','Configuração de flair falhou.')
-                    print('flair fail')
-            if msg.subject == 'remover flair':
-                sub.set_flair(msg.author,'','')
-                r.send_message(msg.author,'flair','Flair removido.')
-                print('remove flair ok')
+        try:
+            for msg in r.get_unread(limit=None):
+                try:
+                    print 'AUTHOR: %s - SUBJECT: %s - BODY: %s' % (msg.author, msg.subject, msg.body)
+                except UnicodeEncodeError:
+                    print 'AUTHOR: %s - unprintable chars' % (msg.author)
+                sub = r.get_subreddit('brasil')
+                if msg.subject == 'flair':
+                    if dbLookup(msg.body):
+                        estado = 'world' if len(msg.body.split(',')) < 2 else msg.body.split(',')[1].strip()
+                        sub.set_flair(msg.author,msg.body,estado)
+                        r.send_message(msg.author,'flair','Flair configurado.')
+                        print('flair ok')
+                    else:
+                        r.send_message(msg.author,'flair','Configuração de flair falhou.')
+                        print('flair fail')
+                if msg.subject == 'remover flair':
+                    sub.set_flair(msg.author,'','')
+                    r.send_message(msg.author,'flair','Flair removido.')
+                    print('remove flair ok')
                 
-            msg.mark_as_read()
+                msg.mark_as_read()
+        except:
+            pass
 
 if __name__ == '__main__':
     main()
-    
\ No newline at end of file
+    

programming_language: Python