=Start=
缘由:
简单整理一下匹配账号密码的正则表达式,方便后面有需要的时候参考。
正文:
参考解答:
注意事项:
双引号有些时候也是需要转义的(可以通过Regex101的提示来进行debug) --" An unescaped delimiter must be escaped; in most languages with a backslash (\)
在正则里面是 \w 但是在Java/HiveSQL代码里面需要用 \\w 来表示(也是需要注意转义的问题)。
\w{0,10}((?i)(access.{0,1}key)|(access.{0,1}token)|(access.{0,1}id)|(secret.{0,1}key)|(secret.{0,1}token)|(api.{0,1}key)|(api.{0,1}secret)|(sign.{0,1}in)|(credential[A-Za-z0-9_\-]{0,22})|ak|sk|akid|skid|auth|authentication|certificate|cookie|session|passwd|password|private|token|salt|secretid|accesskeyid|access_key_id|上线|发布|部署|令牌|凭证|口令|密码|密钥|登录|登陆|私钥|秘钥|认证|证书|帐号|账号|账密|配置|鉴权|验证|数据库|用户名|访问码|账号管理)\s*[=:]\s*\"[A-Za-z0-9_\-]{6,33}\"
key/auth/certificate/cookie/credential/config/pass/passwd/password/private/token/salt
(
|AccessKey
|AccessSecret
|akamaiAccessToken
|akamaiClientSecret
|akamaiClientToken
|AwsSecretId
|AwsSecretKey
|AWS_SESSION_TOKEN
|AzureSubscriptionId
|CredentialAzureAccessKey
|CredentialKeyAli
|CredentialKeyKingsoft
|CredentialKeyTencent
|CredentialSecretAli
|CredentialSecretKingsoft
|CredentialSecretTencent
|CredentialUcloudPrivateKey
|CredentialUcloudPublicKey
|Dockerfile
|GoogleAuthKey
|GoogleProjectId
|WangsuApikey
|_ak
|_sk
|_st
|access
|access.key
|access_key
|accesskey
|aliyun
|api_key
|api_secret
|apisecret
|auth
|cacertdata
|certificate-authority-DATA
|cipher
|clickhouse client
|client-KEY-DATA
|client-certificate-DATA
|client_salt
|clientsalt
|cookie
|credential
|dbproxy
|dockefile
|elastic:
|internal
|kubeconfig
|kubelet-proxy
|kubernetes
|mima
|miyao
|mysql
|pass.
|passwd
|password
|pri_key
|priv_key
|private_key
|proxy
|pwd
|userid
|redis:
|salt
|secret
|secret key
|secret.key
|secret_key
|secretkey
|Secrets-Token
|ssh
|sshkey
|token
|zhanghao
|上线
|发布
|口令
|密码
|密钥
|私钥
|秘钥
|帐号
|账号
|账密
|部署
|配置
|数据库
|用户名
|账号管理
)
question:
请尽可能全面的列出表示Accesskey、secretkey、accesstoken等密钥的关键字
answer:
以下是一些表示Access Key、Secret Key、Access Token等密钥的关键字:
- Access Key 相关:
- Access Key
- AccessKey
- Access_Key
- AccessKeyID
- AccessKeyId
- Access_Key_ID
- AK
- AKID
- Secret Key 相关:
- Secret Key
- SecretKey
- Secret_Key
- SecretAccessKey
- Secret_Access_Key
- SK
- Secret
- Access Token 相关:
- Access Token
- AccessToken
- Token
- AuthToken
- Bearer Token
- Refresh Token
这些关键字通常用于标识和访问各种服务和资源,需要妥善保护以确保系统和数据的安全性。在处理这些密钥时,务必遵循最佳安全实践,如加密存储、限制访问权限、定期轮换密钥等。
question:
请尽可能全面的枚举出一些和账号密码相关的关键字列表,并尝试用一个正则表达式将这些情况匹配出来
answer:
以下是一些和账号密码相关的关键字列表:
- 账号相关:
- Username
- User
- Account
- Login
- UserID
- 用户名
- 账户
- 密码相关:
- Password
- Pass
- Pwd
- 密码
- 口令
- 访问码
- 登录相关:
- Signin
- Sign in
- Sign-in
- 登录
- 登陆
- 登入
- 认证相关:
- Authentication
- Auth
- 认证
- 鉴权
- 验证
- 凭证相关:
- Credential
- Credentials
- 凭证
- 证书
- 令牌
为了匹配这些关键字,可以使用以下正则表达式:
\b(?:Username|User|Account|Login|Email|UserID|用户名|账户|Password|Pass|Pwd|密码|口令|访问码|Signin|Sign in|Sign-in|登录|登陆|登入|Authentication|Auth|认证|鉴权|验证|Credential|Credentials|凭证|证书|令牌)\b
这个正则表达式将匹配上述列出的关键字,可以用于在文本中查找账号密码相关的内容。
regexp_extract(
data,
'("\\w{0,10}((?i)(账号|帐号|密码|口令|秘钥|密钥|token|cookie|pwd|passwd|accesskey|access.key|access_key|secret_key|auth|cipher|secret|_st|zhanghao|mima|用户名|私钥|priv_key|pri_key|private_key|api_key|apisecret|api_secret|kxid|credential|账密|pass.|ssh|上线|发布|部署|client-KEY-DATA|client-certificate-DATA|certificate-authority-DATA|cacertdata|CredentialKeyTencent|CredentialSecretTencent|CredentialKeyKingsoft|CredentialSecretKingsoft|CredentialKeyAli|CredentialSecretAli|CredentialUcloudPrivateKey|CredentialUcloudPublicKey|CredentialAzureAccessKey|AzureSubscriptionId|CredentialJdAccessKey|CredentialJdAccessSecret|AwsSecretId|AwsSecretKey|GoogleAuthKey|GoogleProjectId|WangsuApikey|AkamaiClientToken|AkamaiClientSecret|AkamaiAccessToken|proxy|dbproxy|internal|Dockerfile|sshkey|aliyun|dockefile|kubeconfig|kubelet-proxy|kubernetes|-p|redis:|mysql|elastic:|clickhouse client|数据库|配置|client_salt|clientsalt|账号管理|salt|secretkey|secret.key|secret key|token|secret|auth|password|pwd|access|cipher|salt|mima|miyao|_st|zhanghao))"\\s*[=:]\\s*"[A-Za-z0-9_\-]{6,33}")|("((?!\\w{0,10}(?i)(appkey)).)\\w{0,10}((?i)((api)|(key)|(access)|(token)))\\w{0,10}"\\s*[=:]\\s*"(([0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12})|([0-9A-Z]{32})|(AKIA[0-9A-Z]{16}))")',
0
) as sens_data,
\w 等效的匹配范围是 [a-zA-Z0-9_] (Match a "word" character (Matches any letter, digit or underscore. Equivalent to [a-zA-Z0-9_].))
((?i)((api)|(key)|(access)|(token))) 匹配忽略大小写的 api/key/access/token 单词
"\\s*[=:]\\s*"[A-Za-z0-9_\-]{6,33}" 匹配【":"valueHere"】或者【"="valueHere"】这种情况(冒号/等号两边是可以有空格的)
参考链接:
Regex 101
https://regex101.com/
样例
https://regex101.com/r/vvcHmJ/1
由“正则表达式中的与或非”想到的
https://ixyzero.com/blog/archives/2059.html
[think]如何写出高效率的正则表达式
https://ixyzero.com/blog/archives/2052.html
=END=