Fossil SCM

Further improvements to the attack-spider detection mechanism.

drh 2023-02-08 16:59 trunk
Commit eb7fad0cd3621013177ec8a4604c60bddc5dcb8a22de216718d19aebff5f7b95
2 files changed +2 -2 +11 -4
+2 -2
--- src/cgi.c
+++ src/cgi.c
@@ -1516,11 +1516,11 @@
15161516
Blob content = empty_blob;
15171517
15181518
cgi_set_content(&content);
15191519
style_set_current_feature("test");
15201520
style_header("Malicious Query Detected");
1521
- @ <h2>Begone, Hacker!</h2>
1521
+ @ <h2>Begone, Fiend!</h2>
15221522
@ <p>This page was generated because Fossil believes it has
15231523
@ detected an SQL injection attack. If you believe you are seeing
15241524
@ this in error, contact the developers on the Fossil-SCM Forum. Type
15251525
@ "fossil-scm forum" into any search engine to locate the Fossil-SCM Forum.
15261526
style_finish_page();
@@ -1529,11 +1529,11 @@
15291529
exit(0);
15301530
}
15311531
15321532
/*
15331533
** If looks_like_sql_injection() returns true for the given string, calls
1534
-** cgi_begin_spider() and does not return, else this function has no
1534
+** cgi_begone_spider() and does not return, else this function has no
15351535
** side effects. The range of checks performed by this function may
15361536
** be extended in the future.
15371537
**
15381538
** Checks are omitted for any logged-in user.
15391539
**
15401540
--- src/cgi.c
+++ src/cgi.c
@@ -1516,11 +1516,11 @@
1516 Blob content = empty_blob;
1517
1518 cgi_set_content(&content);
1519 style_set_current_feature("test");
1520 style_header("Malicious Query Detected");
1521 @ <h2>Begone, Hacker!</h2>
1522 @ <p>This page was generated because Fossil believes it has
1523 @ detected an SQL injection attack. If you believe you are seeing
1524 @ this in error, contact the developers on the Fossil-SCM Forum. Type
1525 @ "fossil-scm forum" into any search engine to locate the Fossil-SCM Forum.
1526 style_finish_page();
@@ -1529,11 +1529,11 @@
1529 exit(0);
1530 }
1531
1532 /*
1533 ** If looks_like_sql_injection() returns true for the given string, calls
1534 ** cgi_begin_spider() and does not return, else this function has no
1535 ** side effects. The range of checks performed by this function may
1536 ** be extended in the future.
1537 **
1538 ** Checks are omitted for any logged-in user.
1539 **
1540
--- src/cgi.c
+++ src/cgi.c
@@ -1516,11 +1516,11 @@
1516 Blob content = empty_blob;
1517
1518 cgi_set_content(&content);
1519 style_set_current_feature("test");
1520 style_header("Malicious Query Detected");
1521 @ <h2>Begone, Fiend!</h2>
1522 @ <p>This page was generated because Fossil believes it has
1523 @ detected an SQL injection attack. If you believe you are seeing
1524 @ this in error, contact the developers on the Fossil-SCM Forum. Type
1525 @ "fossil-scm forum" into any search engine to locate the Fossil-SCM Forum.
1526 style_finish_page();
@@ -1529,11 +1529,11 @@
1529 exit(0);
1530 }
1531
1532 /*
1533 ** If looks_like_sql_injection() returns true for the given string, calls
1534 ** cgi_begone_spider() and does not return, else this function has no
1535 ** side effects. The range of checks performed by this function may
1536 ** be extended in the future.
1537 **
1538 ** Checks are omitted for any logged-in user.
1539 **
1540
+11 -4
--- src/lookslike.c
+++ src/lookslike.c
@@ -467,28 +467,35 @@
467467
** Return true if z[i] is the whole word given by zWord
468468
*/
469469
static int isWholeWord(const char *z, unsigned int i, const char *zWord, int n){
470470
if( i>0 && fossil_isalnum(z[i-1]) ) return 0;
471471
if( sqlite3_strnicmp(z+i, zWord, n)!=0 ) return 0;
472
- if( z[i+n]!=0&& fossil_isalnum(z[i+n]) ) return 0;
472
+ if( fossil_isalnum(z[i+n]) ) return 0;
473473
return 1;
474474
}
475475
476476
/*
477477
** Returns true if the given text contains certain keywords or
478
-** punctuation which indicate that it might be SQL. This is only a
479
-** high-level check, not intended to be used for any application-level
480
-** logic other than in defense against spiders in limited contexts.
478
+** punctuation which indicate that it might be an SQL injection attempt
479
+** or some other kind of mischief.
480
+**
481
+** This is not a defense against vulnerabilities in the Fossil code.
482
+** Rather, this is part of an effort to do early detection of malicious
483
+** spiders to avoid them using up too many CPU cycles.
481484
*/
482485
int looks_like_sql_injection(const char *zTxt){
483486
unsigned int i;
484487
if( zTxt==0 ) return 0;
485488
for(i=0; zTxt[i]; i++){
486489
switch( zTxt[i] ){
487490
case ';':
488491
case '\'':
489492
return 1;
493
+ case '/': /* 0123456789 123456789 */
494
+ if( strncmp(zTxt+i+1, "/wp-content/plugins/", 20)==0 ) return 1;
495
+ if( strncmp(zTxt+i+1, "/wp-admin/admin-ajax", 20)==0 ) return 1;
496
+ break;
490497
case 'a':
491498
case 'A':
492499
if( isWholeWord(zTxt, i, "and", 3) ) return 1;
493500
break;
494501
case 'n':
495502
--- src/lookslike.c
+++ src/lookslike.c
@@ -467,28 +467,35 @@
467 ** Return true if z[i] is the whole word given by zWord
468 */
469 static int isWholeWord(const char *z, unsigned int i, const char *zWord, int n){
470 if( i>0 && fossil_isalnum(z[i-1]) ) return 0;
471 if( sqlite3_strnicmp(z+i, zWord, n)!=0 ) return 0;
472 if( z[i+n]!=0&& fossil_isalnum(z[i+n]) ) return 0;
473 return 1;
474 }
475
476 /*
477 ** Returns true if the given text contains certain keywords or
478 ** punctuation which indicate that it might be SQL. This is only a
479 ** high-level check, not intended to be used for any application-level
480 ** logic other than in defense against spiders in limited contexts.
 
 
 
481 */
482 int looks_like_sql_injection(const char *zTxt){
483 unsigned int i;
484 if( zTxt==0 ) return 0;
485 for(i=0; zTxt[i]; i++){
486 switch( zTxt[i] ){
487 case ';':
488 case '\'':
489 return 1;
 
 
 
 
490 case 'a':
491 case 'A':
492 if( isWholeWord(zTxt, i, "and", 3) ) return 1;
493 break;
494 case 'n':
495
--- src/lookslike.c
+++ src/lookslike.c
@@ -467,28 +467,35 @@
467 ** Return true if z[i] is the whole word given by zWord
468 */
469 static int isWholeWord(const char *z, unsigned int i, const char *zWord, int n){
470 if( i>0 && fossil_isalnum(z[i-1]) ) return 0;
471 if( sqlite3_strnicmp(z+i, zWord, n)!=0 ) return 0;
472 if( fossil_isalnum(z[i+n]) ) return 0;
473 return 1;
474 }
475
476 /*
477 ** Returns true if the given text contains certain keywords or
478 ** punctuation which indicate that it might be an SQL injection attempt
479 ** or some other kind of mischief.
480 **
481 ** This is not a defense against vulnerabilities in the Fossil code.
482 ** Rather, this is part of an effort to do early detection of malicious
483 ** spiders to avoid them using up too many CPU cycles.
484 */
485 int looks_like_sql_injection(const char *zTxt){
486 unsigned int i;
487 if( zTxt==0 ) return 0;
488 for(i=0; zTxt[i]; i++){
489 switch( zTxt[i] ){
490 case ';':
491 case '\'':
492 return 1;
493 case '/': /* 0123456789 123456789 */
494 if( strncmp(zTxt+i+1, "/wp-content/plugins/", 20)==0 ) return 1;
495 if( strncmp(zTxt+i+1, "/wp-admin/admin-ajax", 20)==0 ) return 1;
496 break;
497 case 'a':
498 case 'A':
499 if( isWholeWord(zTxt, i, "and", 3) ) return 1;
500 break;
501 case 'n':
502

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button