如何获取 php libcurl 脚本的 wp nonce 值

发布于 2024-08-03 23:03:26 字数 199 浏览 4 评论 0原文

我想在我的 wpmu 安装上自动执行一些管理任务。例如,我正在尝试编写 php curl 脚本来登录和添加新博客。所以我已经通过curl登录,现在我想发布wpmu-blogs.php中的表单,但它隐藏了wp nonce字段。我如何将此值放入变量中?我检查了源代码,但有多个 wp nonce 隐藏字段。我假设不同形式的不同任务有不同的随机数值。我如何获得我需要的 - 用于添加新博客?

I'd like to automate some administrative task for myself on my wpmu install. For example, I'm trying to write php curl script for logging in and adding a new blog. So i'm already logged in via curl and now i want to post form that's in wpmu-blogs.php but it has hidden wp nonce field. How do i get this value into variable? I checked source but there are more than one wp nonce hidden fields. I'm assuming that there are different nonce values for different tasks on different forms. How do i get the one i need - for adding new blog?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

め七分饶幸 2024-08-10 23:03:26

随机数的目的是防止跨站伪造攻击。因此,将定期生成新的随机数值。如果随机数是可预测的,那么它就不会有效。

要使用curl发布到启用nonce的表单,您需要

  1. 打开所有cookie处理选项(将cookie保存到cookie jar,并在保存的cookie jar中发送cookie)

  2. 向包含您的表单的页面发出请求

  3. 使用正则表达式或 HTML/XHTML 解析库,提取您想要的 nonce 值

  4. 有了该值,发布到您想要的页面,同时发送随机数

这种编程可能很乏味。您本质上是在尝试模拟网络浏览器。这是可行的,但您可能需要考虑

  1. 查看Wordpress XML-RPC API 。这是您尝试使用 CURL 自动化执行此类操作的受支持方法,一旦您完成学习曲线,就会变得更加直接。

  2. 还有 AtomPub API。 AtomPub 在某种程度上试图提出一种对网络博客和个人发布网站执行常见操作的标准方法。优点是,理论上,为一个系统(Wordpress)编写的脚本可以在另一个系统(MovableType)上运行。缺点是 AtomPub 功能往往落后于/不同于每个引擎的自定义 API 支持的功能。

  3. 最后,如果您不想学习任何一个 API,您可能想尝试一下 Selenium。 Selenium IDE 将允许您编写 Firefox 脚本并自动处理随机数,因为您实际上是使用浏览器访问每个页面。

The point of a nonce is to protect against a cross site forgery attack. Because of this, a new nonce value is going to be generated on a regular basis. If the nonce was predictable, it wouldn't be effective.

To post to a nonce enabled form using curl, you'd need to

  1. Turn on all cookie handling options (both saving cookies to a cookie jar, and sending cookies in the saved cookie jar)

  2. Make a request to the page that contains your form

  3. Using regular expressions or an HTML/XHTML parsing library, pull out the nonce value you want

  4. With that value in hand, post to the page you want, sending the nonce along

This kind of programming can be tedious. You're essentially trying to emulate a web browser. It's doable, but you may want to consider

  1. Looking into the Wordpress XML-RPC API. This is the supported way of doing the kind of things you're trying to automate with CURL, and will be much more straight forward once you climb the learning curve.

  2. There's also the AtomPub API. AtomPub is, in part, an attempt to come up with a standard way of performing common actions to weblogs and personal publishing sites. The advantage is, in theroy, scripts written for one system (Wordpress) will work on another system (MovableType). The disadvantage is AtomPub features tend to lag behind/differ from features supported in each engine's custom API.

  3. Finally, if you're not up for leaning either API, you might want to give Selenium a try. Selenium IDE will allow you to script Firefox and have the nonce handled automatically, since you're actually using a browser to visit each page.

爱她像谁 2024-08-10 23:03:26

您还可以使用 greasemonkey 来编写您的 Firefox 脚本。

该插件允许自定义网页并使用 JavaScript 执行一些操作。

you can also use greasemonkey to script your firefox.

This addon permit to customize webpage and do some action using javascript.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文