如何在Linux中使用Bash登录网站?
例如,为了登录到Stack Overflow,我尝试了许多不同的方法,如下所示,但没有任何效果。
wget --save-cookies cookies.txt --keep-session-cookies --post-data="username=blahblah&password=blahblahblha" "https://stackoverflow.com/users/login?ssrc=head&returnurl=https%3a%2f%2fstackoverflow.com%2f"
或
curl --user myusername:mypassword https://stackoverflow.com/users/login?ssrc=head&returnurl=https%3a%2f%2fstackoverflow.com%2f -v
我尝试使用Chrome来检查元素以复制curl
请求,但没有成功(可能它依赖于cookie,并且仅在特定时间段内有效)。
请注意,我需要使用用户名和密码登录,而不是使用cookie。
2条答案
按热度按时间byqmnocz1#
仅供娱乐:* 一月一日 *
简介
我的目标是建立一个Bash环境,在这个环境中,当前的控制台(或脚本)可以交互式地处理一个经过验证的HTTPS会话。这可以用来处理大量的IoT目标,处理任何提供商平台来监控个人帐户,等等。
不幸的是,这可能会被错误地用于强调或黑客网络平台(针对任何人),甚至针对Stack Overflow's Fanatic badge(肮脏的骗子!)。
我为任何不当的使用道歉。无论如何,我不对人们做什么负责。
靠近***纯Bash***:仅需要OpenSSL:
...和
gpg
,但您可以自由地以其他方式存储您的 * 凭据 *。准备一些值:
将OpenSSL可执行文件作为后台任务运行:
然后现在,有一个小
doReq
函数来创建两个变量:*$cookie
* 和 *$htstatus
,以及三个数组:$hthead
、$htbody
* 和 *$hterr
*:用途:
doReq /file_part_of_URL [method] [post datas]
让我们登录:
现在出示我的徽章:
在我的table上,我的帐户,这打印:
(just现在)。
当然,你现在可以随时运行
doReq
了,因为连接是打开的。我们现在处于***简介***中引用的 environment/condition 中。(我的站点上的版本做了一个永久循环,以一种更有效的方式请求这个循环,每次 * 取整 * 两分钟(EPOCHSECONDS % 120
),直到用户交互。请参见本文底部。)...
完成后,在退出之前,可以停止
openssl
并关闭file descriptor:(我添加了
ls
和ps
作为 debug 命令。)这说明:
OpenSSL进程完成,所有三个文件描述符都关闭。
您可以在getSo.sh.txt,getSo.sh找到这个脚本(不太精简),它有一个扩展的 * 主循环 *。
**2022-09-29编辑getSo.sh**将
badge1
替换为badge3
。(只有当你已经获得至少一个青铜徽章时脚本才能工作!!这是一个bug,但比以前需要黄金徽章的版本无害。)tv6aics12#
它完全取决于目标网站,但例如,对于堆栈溢出,您可以使用以下命令: