前言:大家在挖比特幣、門羅幣等虛擬貨幣時,需要使用一些挖礦工具,這些工具在運行時需要附加多個參數,或者需要配置參數文件,放在服務器上,所有配置參數都是明文存儲,會被別人輕易的發現並利用。今天我要分享給大家一種方法,可以自己定制挖礦工具,來避免參數明文存儲的問題,還可以制作后門哦。
一、首先簡單介紹下挖礦的流程。
1.申請錢包地址。
1).通過交易網站獲得,例如gateio.io 和aex.com
交易網站可以參考非小號:https://www.feixiaohao.com/
2).通過官網錢包客戶端來生成。
2.下載挖礦工具
本文主要以門羅幣為例,使用的挖礦工具如:xmrig、xmr-stak等。
項目地址:
github.com/xmrig/xmrig(CPU挖礦)
github.com/xmrig/xmrig-amd(amd顯卡挖礦))
http://github.com/xmrig/xmrig-nvidia(nvidia顯卡挖礦)
https://github.com/fireice-uk/xmr-stak(CPU,顯卡挖礦)
xmrig可以按照硬件環境來自由選擇相應版本,而xmr-stak可以編譯成軟件包,一個軟件包即可適用各種硬件環境(CPU、AMD顯卡、Nvidia顯卡)
3、配置挖礦參數
xmrig挖礦參數如下,以魚池為例(f2pool,推薦幾個礦池,見附錄。)
cpu挖礦:xmrig.exe –max-cpu-usage 85 –cpu-priority 3 -o xmr.f2pool.com:13531 -u 錢包地址.礦工名 -p x -k
A卡:xmrig-amd.exe -o xmr.f2pool.com:13531 -u 錢包地址.礦工名 -p x -k
N卡:xmrig-nvidia.exe -o xmr.f2pool.com:13531 -u 錢包地址.礦工名 -p x -k
-a, --algo=ALGO specify the algorithm to use cryptonight cryptonight-lite cryptonight-heavy -o, --url=URL URL of mining server -O, --userpass=U:P username:password pair for mining server -u, --user=USERNAME username for mining server -p, --pass=PASSWORD password for mining server --rig-id=ID rig identifier for pool-side statistics (needs pool support) -t, --threads=N number of miner threads -v, --av=N algorithm variation, 0 auto select -k, --keepalive send keepalived packet for prevent timeout (needs pool support) --nicehash enable nicehash.com support --tls enable SSL/TLS support (needs pool support) --tls-fingerprint=F pool TLS certificate fingerprint, if set enable strict certificate pinning -r, --retries=N number of times to retry before switch to backup server (default: 5) -R, --retry-pause=N time to pause between retries (default: 5) --cpu-affinity set process affinity to CPU core(s), mask 0x3 for cores 0 and 1 --cpu-priority set process priority (0 idle, 2 normal to 5 highest) --no-huge-pages disable huge pages support --no-color disable colored output --variant algorithm PoW variant --donate-level=N donate level, default 5% (5 minutes in 100 minutes) --user-agent set custom user-agent string for pool -B, --background run the miner in the background -c, --config=FILE load a JSON-format configuration file -l, --log-file=FILE log all output to a file -S, --syslog use system log for output messages --max-cpu-usage=N maximum CPU usage for automatic threads mode (default 75) --safe safe adjust threads and av settings for current CPU --asm=ASM ASM code for cn/2, possible values: auto, none, intel, ryzen. --print-time=N print hashrate report every N seconds --api-port=N port for the miner API --api-access-token=T access token for API --api-worker-id=ID custom worker-id for API --api-id=ID custom instance ID for API --api-ipv6 enable IPv6 support for API --api-no-restricted enable full remote access (only if API token set) --dry-run test configuration and exit -h, --help display this help and exit -V, --version output version information and exit
二、定制挖礦工具xmrig
1. ..\src\common\config\CommonConfig.cpp //配置默認參數以及礦池地址、錢包地址和密碼。
xmrig::CommonConfig::CommonConfig() :
xmrig::CommonConfig::CommonConfig() :
m_algorithm(CRYPTONIGHT, VARIANT_AUTO), //設置挖礦算法,默認為CRYPTONIGHT
m_adjusted(false),
m_apiIPv6(false),
m_apiRestricted(true),
m_autoSave(true),
m_background(false), //如果為true則軟件后台挖礦,不顯示窗口,只創建進程。
m_colors(true), //設置顏色主題
m_dryRun(false),
m_syslog(false),
# ifdef XMRIG_PROXY_PROJECT
m_watch(true),
# else
m_watch(false), // TODO: enable config file watch by default when this feature propertly handled and tested.
# endif
m_apiPort(0),
m_donateLevel(kDefaultDonateLevel), //kDefaultDonateLevel為軟件抽水比例,默認為百分之五,最小值為百分之一。即最小可以設置為1。
m_printTime(60),
m_retries(5),
m_retryPause(5),
m_state(NoneState)
{
m_pools.push_back(Pool(“礦池地址”,端口,”錢包地址”,”x”)); //端口為數字類型
# ifdef XMRIG_PROXY_PROJECT
m_retries = 2;
m_retryPause = 1;
# endif
}
2. ..\src\donate.h //設置軟件抽水比例
constexpr const int kDefaultDonateLevel = 5; //抽水比例為百分之五,可以設置為1,同上。
constexpr const int kMinimumDonateLevel = 1;
3. ..\src\core\Config.cpp //設置CPU參數
xmrig::Config::Config() : xmrig::CommonConfig(),
m_aesMode(AES_AUTO),
m_algoVariant(AV_AUTO),
m_assembly(ASM_AUTO),
m_hugePages(true), //設置大內存交換,提高挖礦性能,需要配置系統參數
m_safe(true), //設置CPU安全使用參數,可以在系統資源緊張時,降低軟件使用CPU資源的比例。
m_shouldSave(false),
m_maxCpuUsage(75), //設置CPU最大使用率,默認為%75
m_priority(-1)
三、編譯xmrig(以widows 32位版本為例)
1、下載編譯工具
下載依賴包,解壓至C盤: https://github.com/xmrig/xmrig-deps/releases.
安裝MSYS2:
http://repo.msys2.org/distrib/x86_64/msys2-x86_64-20180531.exe
http://repo.msys2.org/distrib/i686/msys2-i686-20180531.exe
安裝gcc等編譯環境
pacman -Sy
pacman -S mingw-w64-i686-gcc
pacman -S make
pacman -S mingw-w64-i686-cmake
pacman -S mingw-w64-i686-pkg-config
2、編譯32位版本的xmrig
在xmrig的根目錄下創建build文件夾:
mkdir build
cd build
使用cmake編譯
cmake .. -G "Unix Makefiles" -DXMRIG_DEPS=c:/xmrig-deps-3.3/gcc/x86 -DWITH_HTTPD=OFF -DWITH_TLS=OFF
使用make編譯
make -j4
-DWITH_LIBCPUID=OFF Disable libcpuid. Auto configuration of CPU after this will be very limited.
-DWITH_AEON=OFF Disable CryptoNight-Lite support.
-DWITH_HTTPD=OFF Build without built in http server and API.
-DWITH_TLS=OFF Disable SSL/TLS support.
-DWITH_ASM=OFF Disable ASM accelerated
行文有些粗糙,難免有些紕漏,還望讀者海涵。有錯誤之處,望指正。
附礦池列表:(僅供參考)
國內:
魚池:https://www.f2pool.com/
星火礦池:http://xmr.sparkpool.com/
國池:https://xmr.chinaenter.cn/#/home
皮皮蝦礦池:https://xmr.c1d2.com/
nanopool:https://xmr.nanopool.org/
國外:
http://minexmr.com/
https://cn.minergate.com/xmr-mining-pool