הערה: הקישורים במאמר זה כוללים קישורי שותפים לאמזון. לא תחויב בשום תשלום נוסף עבור לחיצה על קישורים אלה, אך תתמוך בי אם תבחר לרכוש משהו דרך אחד מהקישורים הללו. תוֹדָה!
היומנים שלך מלאים ב-404 כניסות ב- /.DS_Store
, /backup.sql
, /.vscode/sftp.json
ובמספר רב של כתובות אתרים אחרות. בעוד שבקשות אלו לרוב אינן מזיקות, אלא אם כן, כמובן, לשרת שלך יש באמת מה להציע במקומות הללו, עליך להרגיע את הרובוטים.
מַדוּעַ?
פגיעה בשרת היא משימה עתירת משאבים, ובהתחשב בכך שלבוטים האלה יש רשימה נרחבת של כתובות URL שונות, אין מנגנון שמירה במטמון שיכול לעזור לך. חוץ מזה, עצירת בוטים היא תמיד אמצעי בטיחותי.
השתמשנו בעבר ב-HAProxy כדי למתן התקפות על דף ההתחברות של וורדפרס , הרעיון הוא להרחיב את הגישה הזו לכיסוי גם שגיאות 404.
בוטים ינסו כמיטב יכולתם ליצור הרס בשרת שלך
שאבתי השראה מ-Sasa Tekovic , כלומר על אי חסימת סורקים בפועל של מנועי חיפוש ואפשרות ל-404 על משאבים סטטיים כדי למנוע משאבים חסרים בפועל - שגיאה מצידך - לא לחסום משתמשים לגיטימיים.
לפני היישום, תמיד טוב ליצור סביבת בדיקה מקומית. בואו נתחיל HAProxy
ו- Apache
באמצעות Docker
. אנחנו צריכים שרת אחורי אמיתי שייתן לנו את 404
האלה.
version : '3' services: haproxy: image: haproxy:3.1.3-alpine ports: - "8100:80" volumes: - "./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg" networks: - webnet apache: image: httpd:latest container_name: apache1 ports: - "8080:80" volumes: - ./html:/usr/local/apache2/htdocs/ networks: - webnet networks: webnet:
לאחר מכן, פשוט הפעל docker-compose up
ותוכל לגשת ל- localhost:8100
בדפדפן שלך.
הקובץ haproxy.cfg
הוא די מובן מאליו:
global log stdout format raw daemon debug defaults log global mode http frontend main bind *:80 acl static_file path_end .css .js .jpg .jpeg .gif .ico .png .bmp .webp .csv .ttf .woff .svg .svgz acl excluded_user_agent hdr_reg(user-agent) -i (yahoo|yandex|kagi|(google|bing)bot) # tracks IPs but exclude hits on static files and search engine crawlers http-request track-sc0 src table mock_404_tracking if !static_file !excluded_user_agent # increment gpc0 if response code was 404 http-response sc-inc-gpc0(0) if { status 404 } # checks if the 404 error rate limit was exceeded http-request deny deny_status 403 content-type text/html lf-string "404 abuse" if { sc0_gpc0_rate(mock_404_tracking) ge 5 } # whatever backend you're using use_backend apache_servers backend apache_servers server apache1 apache1:80 maxconn 32 # mock backend to hold a stick table backend mock_404_tracking stick-table type ip size 100k expire 10m store gpc0,gpc0_rate(1m)
אם תקבל יותר מ-5 כניסות ל-404 בקשות בדקה בודדת, הבוט ייחסם ל-10 דקות.
כפי שהיא עומדת, הגדרה זו מגבילה למעשה את הקצב של בוטים שיוצרים 404 מוגזמים. עם זאת, אנחנו רוצים גם לשלב אותו עם הדוגמה הקודמת שלנו, שבה השתמשנו ב- HAProxy
כדי לחסום התקפות על WordPress
.
global log stdout format raw daemon debug defaults log global mode http frontend main bind *:80 # We may, or may not, be running this with Cloudflare acting as a CDN. # If Cloudflare is in front of our servers, user/bot IP will be in # 'CF-Connecting-IP', otherwise user IP with be in 'src'. So we make # sure to set a variable 'txn.actual_ip' that has the IP, no matter what http-request set-var(txn.actual_ip) hdr_ip(CF-Connecting-IP) if { hdr(CF-Connecting-IP) -m found } http-request set-var(txn.actual_ip) src if !{ hdr(CF-Connecting-IP) -m found } # gets the actual IP on logs log-format "%ci\ %hr\ %ft\ %b/%s\ %Tw/%Tc/%Tt\ %B\ %ts\ %r\ %ST\ %Tr IP:%{+Q}[var(txn.actual_ip)]" # common static files where we may get 404 errors and also common search engine # crawlers that we don't want blocked acl static_file path_end .css .js .jpg .jpeg .gif .ico .png .bmp .webp .csv .ttf .woff .svg .svgz acl excluded_user_agent hdr_reg(user-agent) -i (yahoo|yandex|kagi|google|bing) # paths where we will rate limit users to prevent Wordpress abuse acl is_wp_login path_end -i /wp-login.php /xmlrpc.php /xmrlpc.php acl is_post method POST # 404 abuse blocker # track IPs but exclude hits on static files and search engine crawlers # increment gpc0 counter if response status was 404 and deny if rate exceeded http-request track-sc0 var(txn.actual_ip) table mock_404_track if !static_file !excluded_user_agent http-response sc-inc-gpc0(0) if { status 404 } http-request deny deny_status 403 content-type text/html lf-string "404 abuse" if { sc0_gpc0_rate(mock_404_track) ge 5 } # wordpress abuse blocker # track IPs if the request hits one of the monitored paths with a POST request # increment gpc1 counter if path was hit and deny if rate exceeded http-request track-sc1 var(txn.actual_ip) table mock_wplogin_track if is_wp_login is_post http-request sc-inc-gpc1(1) if is_wp_login is_post http-request deny deny_status 403 content-type text/html lf-string "login abuse" if { sc1_gpc1_rate(mock_wplogin_track) ge 5 } # your backend, here using apache for demonstration purposes use_backend apache_servers backend apache_servers server apache1 apache1:80 maxconn 32 # mock backends for storing sticky tables backend mock_404_track stick-table type ip size 100k expire 10m store gpc0,gpc0_rate(1m) backend mock_wplogin_track stick-table type ip size 100k expire 10m store gpc1,gpc1_rate(1m)
לרוץ עם שני stick tables
, ולעצור את שני האיומים.
והנה לך. HAProxy שוב השתמשה בהרבה יותר מאשר כפרוקסי הפוך פשוט. זה סכין שוויצרית קטנה!
פנס ראש זה היה מחליף משחק בעת עבודה על תיקונים.
היה לי אחד, אבל כשהוא נשבר, היססתי להחליף אותו, נעזר בפנס הטלפון. ובטח, זה עובד - אבל ברגע שאתה חווה את הנוחות שבשתי ידיים חופשיות שוב - אין דרך חזרה. אם אתה צריך תאורה אמינה ללא ידיים, זה חובה!
פוסט זה פורסם במקור ב- https://wasteofserver.com/stop-404-prying-bots-with-haproxy/ , ייתכן שתמצא שם תיקונים חדשים יותר והערות נוספות.