定制 dapphp/torutils 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dapphp/torutils

Composer 安装命令:

composer require dapphp/torutils

包简介

Classes for interacting with Tor over the control protocol, querying directory authorities and servers, DNS exit lists, a curl wrapper that makes it easy to use Tor's SOCKS proxy, and more.

README 文档

README

Build Status Total Downloads Latest Stable Version

Name:

Dapphp\TorUtils - Classes for interacting with Tor over the control protocol, querying directory authorities and servers, DNS exit lists, a curl wrapper that makes it easy to use Tor's SOCKS proxy, and more.

Version:

1.15.3

Author:

Drew Phillips drew@drew-phillips.com

Requirements:

  • PHP 5.5 or greater

Description:

Dapphp\TorUtils provides some PHP libraries for working with Tor. The main functionality focuses on interacting with Tor using the Tor control protocol and provides many methods to make it easy to send commands, retrieve directory and node information, and modify Tor's configuration using the control protocol. A few other utility classes are provided for robustness.

The following classes are provided:

  • ControlClient: A class for interacting with Tor's control protocol which can be used to script your Tor relay or learn information about other nodes in the Tor network. With this class you can query directory information through the controller, get and set Tor configuration values, fetch information with the GETINFO command, subscribe to events, and send raw commands to the controller and get back parsed responses.

  • DirectoryClient: A class for querying information directly from Tor directory authorities (or any other Tor directory server). This class can be used to fetch information about active nodes in the network by nickname or fingerprint or retrieve a list of all active nodes to get information such as IP address, contact info, exit policies, certs, uptime, flags and more.

  • TorDNSEL: A simple interface for querying an address against the Tor DNS exit lists to see if an IP address belongs to a Tor exit node.

  • TorCurlWrapper: A wrapper for cURL that ensures HTTP requests are proxied through Tor using SOCKS5 with DNS resolution over Tor (if supported). It also turns cURL errors into an Exception and parses responses into headers and body parts.

Basic Example:

This library provides a lot of different functionality (see examples directory) and a wide range of possibility but a common use case is sending a signal to the Tor controller to change IP addresses. This shows how to do just that:

<?php

require_once 'vendor/autoload.php'; // using composer

use Dapphp\TorUtils\ControlClient;

$tc = new ControlClient();

try {
    $tc->connect(); // connect to 127.0.0.1:9051
    $tc->authenticate('password'); // can also use cookie or empty auth
    $tc->signal(ControlClient::SIGNAL_NEWNYM);
    echo "Signal sent - IP changed successfully!\n";
} catch (\Exception $ex) {
    echo "Signal failed: " . $ex->getMessage() . "\n";
}

Examples:

The source package comes with several examples of interacting with the Tor control protocol and directory authorities. See the examples/ directory in the source package.

Currently, the following examples are provided:

  • dc_GetAllDescriptors-simple.php: Uses the DirectoryClient class to query a directory authority for a list of all currently known descriptors and prints basic information on each descriptor.

  • dc_GetServerDescriptor-simple.php: Uses the DirectoryClient to fetch info about a single descriptor and prints the information.

  • tc_AsyncEvents.php: Uses the ControlClient to subscribe to some events which the controller will send to a registered callback as they are generated.

  • tc_GetConf.php: Uses the ControlClient to interact with the controller to fetch and set Tor configuration options.

  • tc_GetInfo.php: Uses ControlClient to talk to the Tor controller to get various pieces of information about the controller and routers on the network.

  • tc_NewNym.php: Uses ControlClient to send the "NEWNYM" signal to the controller to change IP addresses (as shown above).

  • tc_CreateHiddenService.php: Tells the controller to create a new Onion ("Hidden") Service. This example shows how to programatically add a new hidden service, delete it, and re-create it with the private key that was generated. The private key can be securely stored to restart the service at a later time using the same onion address.

  • tc_SendData.php: Shows how to use ControlClient to send arbitrary commands and read the response from the controller. Replies are returned as ProtocolReply objects which give easy access to the status of the reply (e.g. success/fail) and provides methods to access individual reply lines or iterate over each line and process the data.

  • TorDNSEL.php: An example of using the Tor DNS Exit Lists to check if a remote IP address connecting to a specific IP:Port combination is a Tor exit router.

  • CurlWrapper.php: Shows how to use the cURL wrapper class to make HTTP requests through the Tor socks proxy.

  • CurlCountry.php: Shows how to use Exit Nodes from a specific country with the cURL wrapper.

TODO:

The following commands are not directly implemented by ControlClient and would need to be implemented or the implementation could communicate directly with the controller using the provided functions to issue commands:

  • RESETCONF
  • SAVECONF
  • MAPADDRESS
  • EXTENDCIRCUIT
  • SETCIRCUITPURPOSE
  • ATTACHSTREAM
  • POSTDESCRIPTOR
  • REDIRECTSTREAM
  • CLOSESTREAM
  • CLOSECIRCUIT
  • USEFEATURE
  • LOADCONF
  • TAKEOWNERSHIP
  • DROPGUARDS
  • HSFETCH
  • HSPOST

Copyright:

Copyright (c) 2022 Drew Phillips
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

- Redistributions of source code must retain the above copyright notice,
  this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

Donate:

BTC: 1dJyNBaKBqRXVVMw5uVPyz7M3tMrh3gU2 ETH: 0x51A1057D485da13fB9C37C8ed3C5B3BA59e950D1 Flattr: OpenInternet

dapphp/torutils 适用场景与选型建议

dapphp/torutils 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 86.23k 次下载、GitHub Stars 达 72, 最近一次更新时间为 2015 年 10 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「curl」 「tor」 「anonynimity」 「onion」 「tor client」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 dapphp/torutils 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 dapphp/torutils 我们能提供哪些服务?
定制开发 / 二次开发

基于 dapphp/torutils 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 86.23k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 73
  • 点击次数: 26
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 72
  • Watchers: 9
  • Forks: 10
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2015-10-11