1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
Blind SQL Injection in Gogs label search ======================================== Researcher: Timo Schmid <tschmid@ernw.de> Description =========== Gogs(Go Git Service) is a painless self-hosted Git Service written in Go. (taken from [1]) It is very similiar to the github hosting plattform. Multiple users can create multiple repositories and share code with others with the git version control system. Repositories can be marked as public or private to prevent access from unauthorized users. Gogs provides a view to filter issues by labels. This view is accessible at /<username>/<repository>/issues?labels=&type=&state= The labels Parameter of this view is vulnerable to a blind SQL injection. Exploitation Technique: ======================= Remote Severity Level: =============== Critical CVSS Base Score =============== 6.6 (AV:N / AC:H / Au:N / C:C / I:P / A:P) CVE-ID ====== CVE-2014-8681 Impact ====== The vulnerability results at least in a complete compromise of the database. Depending on the particular database configuration a compromise of the system is also possible. Status ====== Fixed by Vendor Vulnerable Code Section ======================= models/issue.go: [...] // GetIssues returns a list of issues by given conditions. func GetIssues(uid, rid, pid, mid int64, page int, isClosed bool, labelIds, sortType string) ([]Issue, error) { sess := x.Limit(20, (page-1)*20) if rid > 0 { sess.Where("repo_id=?", rid).And("is_closed=?", isClosed) } else { sess.Where("is_closed=?", isClosed) } if uid > 0 { sess.And("assignee_id=?", uid) } else if pid > 0 { sess.And("poster_id=?", pid) } if mid > 0 { sess.And("milestone_id=?", mid) } if len(labelIds) > 0 { for _, label := range strings.Split(labelIds, ",") { sess.And("label_ids like '%$" + label + "|%'") } } [...] The vulnerability exists because of a string concatination in the SQL query with user supplied data. A attacker is restricted to not use commas in the injection string as the program splits input at commas. Proof of Concept ================ Test of version string contains at least 10 characters: http://www.example.com/user/repos/issues?label=' or char_length(@@version) > 10 and '|%'='&type=all&state= Returns all issues if true, non if false. This could be used to extract data with a binary search. Solution ======== This vulnerability could easily be fixed by using prepared statements: sess.And("label_ids like ?", "%$" + label + "|%") Update to Version 0.5.6.1025. Affected Versions ================= >= v0.3.1-9-g49dc57e <= v0.5.6.1024-gf1d8746 Timeline ======== 2014-09-25: Developer informed 2014-10-16: Contact of developer regarding fix 2014-10-25: Working together with developer on fix 2014-10-25: Fixed by ensuring datatype of user input 2014-11-14: CVE-ID assigned Credits ======= Pascal Turbing <pturbing@ernw.de> Jiahua (Joe) Chen <u@gogs.io> References ========== [1] https://github.com/gogits/gogs [2] http://gogs.io/ [3] <blockquote class="wp-embedded-content" data-secret="8SemxwC52w"><a href="https://insinuator.net/2012/05/sql-injection-testing-for-business-purposes-part-1/" target="_blank"rel="external nofollow" class="external" >SQL Injection Testing for Business Purposes Part 1</a></blockquote><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted" style="position: absolute; visibility: hidden;" title="“SQL Injection Testing for Business Purposes Part 1” — Insinuator.net" src="https://insinuator.net/2012/05/sql-injection-testing-for-business-purposes-part-1/embed/#?secret=dAWxF7iG77#?secret=8SemxwC52w" data-secret="8SemxwC52w" frameborder="0" marginmarginscrolling="no"></iframe> [4] <blockquote class="wp-embedded-content" data-secret="uGbymE6eZw"><a href="https://insinuator.net/2012/05/sql-injection-testing-for-business-purposes-part-2/" target="_blank"rel="external nofollow" class="external" >SQL Injection Testing for Business Purposes Part 2</a></blockquote><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted" style="position: absolute; visibility: hidden;" title="“SQL Injection Testing for Business Purposes Part 2” — Insinuator.net" src="https://insinuator.net/2012/05/sql-injection-testing-for-business-purposes-part-2/embed/#?secret=RG164nV3xb#?secret=uGbymE6eZw" data-secret="uGbymE6eZw" frameborder="0" marginmarginscrolling="no"></iframe> [5] <blockquote class="wp-embedded-content" data-secret="g7qn1zH7YA"><a href="https://insinuator.net/2012/06/sql-injection-testing-for-business-purposes-part-3/" target="_blank"rel="external nofollow" class="external" >SQL Injection Testing for Business Purposes Part 3</a></blockquote><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted" style="position: absolute; visibility: hidden;" title="“SQL Injection Testing for Business Purposes Part 3” — Insinuator.net" src="https://insinuator.net/2012/06/sql-injection-testing-for-business-purposes-part-3/embed/#?secret=AXLF33b43z#?secret=g7qn1zH7YA" data-secret="g7qn1zH7YA" frameborder="0" marginmarginscrolling="no"></iframe> [6] https://www.ernw.de/download/BC-1401.txt Advisory-ID =========== BC-1401 Disclaimer ========== The information herein contained may change without notice. Use of this information constitutes acceptance for use in an AS IS condition. There are NO warranties, implied or otherwise, with regard to this information or its use. Any use of this information is at the user's risk. In no event shall the author/ distributor be held liable for any damages whatsoever arising out of or in connection with the use or spread of this information. -- Timo Schmid ERNW GmbH, Carl-Bosch-Str. 4, 69115 Heidelberg-www.ernw.de Tel. +49 6221 480390 - Fax 6221 419008 - Cell +49 151 16227192 PGP-FP 971B D4F7 5DD1 FCED 11FC 2C61 7AB6 927D 6F26 6CE0 Handelsregister Mannheim: HRB 337135 Geschaeftsfuehrer: Enno Rey ============================================================== || Blog: www.insinuator.net | | Conference: www.troopers.de || ============================================================== ================== TROOPERS15 ================== * International IT Security Conference & Workshops * 16th - 20st March 2015 / Heidelberg, Germany * www.troopers.de ==================================================== |