当前位置:网站首页>Security Basics 4 - regular expressions
Security Basics 4 - regular expressions
2022-07-25 19:35:00 【Hold the kitten】
Regular expressions
Definition
Also known as regular expression ,(Regular Expression, In code it is often abbreviated as regex、regexp or RE), It's a text pattern , Include normal characters ( for example ,a To z Between the letters ) And special characters ( be called " Metacharacters "), yes Computer science A concept of . Regular expressions Use a single string to describe it 、 Match a string that matches a syntax rule , Usually used to retrieve 、 Replace those that match a pattern ( The rules ) The text of .
Metacharacters
| character | describe |
|---|---|
| \ | Mark the next character as a special character 、 Or an original character 、 Or a Backward reference 、 Or an octal escape character . for example ,'n' Matching character "n".'\n' Match a line break . Sequence '\\' matching "\" and "\(" The match "(". |
| ^ | Matches the start of the input string . If set RegExp Object's Multiline attribute ,^ Also match '\n' or '\r' The position after . |
| $ | Matches the end of the input string . If set RegExp Object's Multiline attribute ,$ Also match '\n' or '\r' Previous position . |
| * | Match previous subexpression zero or more times . for example ,zo* Can match "z" as well as "zoo".* Equivalent to {0,}. |
| + | Match previous subexpression one or more times . for example ,'zo+' Can match "zo" as well as "zoo", But can't match "z".+ Equivalent to {1,}. |
| ? | Match previous subexpression zero or once . for example ,"do(es)?" Can match "do" or "does" .? Equivalent to {0,1}. |
| \b | Matches a word boundary , That is, the position between the word and the space . for example , 'er\b' Can match "never" Medium 'er', But can't match "verb" Medium 'er'. |
| \B | Match non word boundaries .'er\B' Can match "verb" Medium 'er', But can't match "never" Medium 'er'. |
| \cx | Match by x Control characters indicated . for example , \cM Match one Control-M Carriage return .x The value of must be A-Z or a-z One of . otherwise , take c As an original 'c' character . |
| \d | Matches a numeric character . Equivalent to [0-9]. |
| \D | Matches a non-numeric character . Equivalent to [^0-9]. |
| \f | Match a page break . Equivalent to \x0c and \cL. |
| \n | Match a line break . Equivalent to \x0a and \cJ. |
| \r | Match a carriage return . Equivalent to \x0d and \cM. |
| \s | Matches any whitespace characters , Including Spaces 、 tabs 、 Page breaks and so on . Equivalent to [ \f\n\r\t\v]. |
| \S | Matches any non-whitespace characters . Equivalent to [^ \f\n\r\t\v]. |
| \t | Match a tab . Equivalent to \x09 and \cI. |
| \v | Match a vertical tab . Equivalent to \x0b and \cK. |
| \w | Match the letter 、 Numbers 、 Underline . Equivalent to '[A-Za-z0-9_]'. |
| \W | Match nonletter 、 Numbers 、 Underline . Equivalent to '[^A-Za-z0-9_]'. |
| \n | Identifies an octal escape value or a backward reference . If \n At least before n Get subexpressions , be n For backward reference . otherwise , If n It's octal (0-7), be n Is an octal escape value . |
Common regular expressions
| Regular expressions | describe |
|---|---|
| /\b([a-z]+) \1\b/gi | The position of a word in succession . |
| /(\w+):\/\/([^/:]+)(:\d*)?([^# ]*)/ | Match one URL Resolve to protocol 、 Domain 、 Port and relative path . |
| /^(?:Chapter|Section) [1-9][0-9]{0,1}$/ | Position the chapter . |
| /[-a-z]/ | a to z common 26 individual Letters plus one - Number . |
| /ter\b/ | Can match chapter, It doesn't match terminal. |
| /\Bapt/ | Can match chapter, It doesn't match aptitude. |
| /Windows(?=95 |98 |NT )/ | Can match Windows95 or Windows98 or WindowsNT, When a match is found , from Windows After that, the next retrieval matching will be carried out . |
| /^\s*$/ | Match blank line . |
| /\d{2}-\d{5}/ | The verification consists of two digits 、 A hyphen plus 5 It's made up of numbers ID Number . |
| <[a-zA-Z]+.*?>([\s\S]*?) | matching HTML Mark . |
Regular expression cases
Case study 1: Use regular expressions to solve the length problem
requirement : Regular expressions :(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&*\\\.\(\)])
location 8-16 position
analysis :
(?=.*[0-9]): character + Numbers

(?=.*[0-9])(?=.*[a-z]): character + Numbers + Lowercase letters

(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]): character + Numbers + Lowercase letters + Capital

(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&*\\\.\(\)]): character + Numbers + Lowercase letters + Capital + Special characters

(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&*\\\.\(\)])(?=^.{8,16}$): character + Numbers + Lowercase letters + Capital + Special characters + The shortest 8 The longest bit 16 position
1、 No, 8 Bit character time

2、 Yes 8 Bit but less than 16 Bit character time

3、 More than 16 characters
Case study 2: Use regular expressions to bypass web pages
Environmental Science :sqllabs shooting range
1、 First, we can get that the data table has three columns , utilize order by When the number of columns is different during joint query, there will be error information to test .

2、 Judge the data display position

3、 View the current database name

4、 Check the current user and hostname

5、 Get all library names

6、 Get all table names : http://127.0.0.1:8003/Less-1/?id=-1%27%20union%20select%201,group_concat(table_name),3%20from%20information_schema.tables%20where%20table_schema=%27security%27--+

7、 obtain users Information in the table :http://127.0.0.1:8003/Less-1/?id=-1%27%20union%20select%201,(select%20group_concat(username,0x3a,password)from%20users),3--+

Reference resources :
Regular expressions _ Baidu Encyclopedia
边栏推荐
- Gbase 8s UDR memory management_ 03_ mi_ realloc
- Basic practice of Blue Bridge Cup - shape retrieval of matrix (C language)
- 微信小程序开发之WXSS模板样式与WXS脚本语言
- [wp]ctfshow-web getting started - Explosion
- Siemens-PLM-TeamCenter下载、安装、使用教程
- 【刷题记录】21. 合并两个有序链表
- Imeta | sangerbox: interactive integrated clinical information analysis platform
- Add a subtitle of 3D effect to the container
- 919. 完全二叉树插入器
- 平衡二叉树
猜你喜欢

新瓶装老酒--近期APT32(海莲花)组织攻击活动样本分析

Talk about 11 tips for interface performance optimization
![[wp]ctfshow-web getting started - Explosion](/img/4b/6d8f4c044578382b9353d4d1c69c8f.png)
[wp]ctfshow-web getting started - Explosion

Dynamic implementation of wechat applet 27 progress bar and static construction of search box and hot search list

手机端触摸图片slider轮播插件photoswipe.js

NPM semantic version control, solution console prop being mutated: "placement" error

Hash undirected graph visualization

Common misunderstandings caused by a time reporting assistant of Blue Bridge Cup basic questions

Wechat campus maintenance and repair application applet graduation design finished product of applet completion work (6) opening defense ppt
![[record of question brushing] 21. Merge two ordered linked lists](/img/81/5f1ab0054ef5e8cba32f7a546a64c4.png)
[record of question brushing] 21. Merge two ordered linked lists
随机推荐
485 current acquisition module dam-8041
Grid layout frequently asked interview questions
Siemens PLM Teamcenter download, installation and use tutorial
Wechat campus maintenance and repair applet graduation design finished product (7) Interim inspection report
Small program completion work wechat campus maintenance application small program graduation design finished product (2) small program function
QIIME2得到PICRUSt2结果后如何分析
Network design and planning of a company
919. Complete binary tree inserter
什么是唯心主义
相机内参矩阵K和fov的相互转换
Openresty Lua resty mlcache multi-level cache
A high efficiency 0-delay 0-copy QT player scheme based on Hisilicon 3559
Nezha d1-h test microbench
GBASE 8s UDR内存管理_02_mi_dalloc
Oracle database download, installation, use tutorial and problem summary
微信小程序开发之全局配置与页面配置
高端旗舰投影仪选购指南:当贝X3 Pro、当贝F5观影更沉浸!
balanced binary tree
平衡二叉树
帝国CMS整站|手机号/QQ靓号商城源码|适配移动端