Linux Fuck Windows

开一个Linux监控Windows系列的大坑

先从不同版本的winexe搞起

Winexe 0.80

这里选择的代码是 https://github.com/greenbone/openvas-smb

原因是最近还有在更新

1
[/root/test/openvas-smb-21.4.0/winexe/winexe.c:90:parse_args()] winexe version 0.80

编译

分别记录一下Fedora和CentOS7两种系统下的编译过程

搞了两套是因为

  • CentOS7的EPEL源移除了mingw相关的包
  • 在Fedora上编译完之后要迁往CentOS7,要同时迁移N多依赖,也很不方便

先说一下共有问题

No package ‘heimdal-gssapi’ found

dnf/yum出来的heimdal-devel不支持pkgconfig,后续许多操作都很麻烦,建议按下面的方法自己先compile一个

https://community.greenbone.net/t/full-gvm-11-build-guide-for-centos-8/5425

1
2
3
4
5
6
7
./configure --enable-otp=no --prefix=/opt/heimdal
make && make install

echo "/opt/heimdal/lib" > /etc/ld.so.conf.d/heimdal-xxx.conf
ldconfig

export PKG_CONFIG_PATH=/opt/heimdal/lib/pkgconfig

ld -ltspi

ld问题参考 https://www.hbspy.moe/2021/06/07/ld_cannot_find/

1
ln -s /usr/lib64/libtspi.so.1 /usr/lib64/libtspi.so

Fedora 编译

mingw can no longer be found in the Centos 7 EPEL Repository See bugzilla.redhat.com/show_bug.cgi?id=1807975 and pagure.io/fesco/issue/2333

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
yum install gcc cmake pkg-config mingw64-gcc gnutls-devel \
perl-base popt-devel glib2-devel \
libunistring-devel krb5-devel

yum install mingw32-gcc-c++ \
mingw32-gcc \
mingw32-pthreads \
mingw32-w32api \
mingw32-binutils \
mingw32-runtime \
mingw32-filesystem \
mingw32-cpp \
mingw32-dlfcn-static

mkdir build
cd build
cmake ..
make && make install

https://wiki.videolan.org/Win32Compile_Under_Fedora/

CentOS7 编译

CentOS7多一个popt的问题,类似heimdal,也是yum出来的包不支持pkgconfig

参照heimdal的处理自己先compile一个

1
2
3
4
5
6
7
8
./autogen.sh
./configure --prefix=/opt/popt
make && make install

echo "/opt/popt/lib/" > /etc/ld.so.conf.d/popt.conf
ldconfig

export PKG_CONFIG_PATH=/opt/popt/lib/pkgconfig

主要需要搞定mingw的问题

这里分享一个可用的repo: https://copr.fedorainfracloud.org/coprs/alonid/mingw-epel7/

使用的时候需要只enable它,yum install --disablerepo=* --enablerepo=mingw-epel7 xxx

常见问题

NT_STATUS_IO_TIMEOUT

  1. 一种可能是0.80似乎只支持SBMv1

smb1protocol

https://docs.microsoft.com/zh-cn/windows-server/storage/file-server/troubleshoot/detect-enable-and-disable-smbv1-v2-v3

顺便分享一些远程安装启用的命令

是在Windows下使用的

首先利用SysinternalsSuite包中提供的PsExec拉Dism,用WMIC process call create应该也行

NOTE 这里加了/NoRestart,主要是由于Dism提供的重启不够强力,可能造成卡住

后面用WMIC shutdown -r -f强制重启

1
2
.\PsExec.exe \\[IP] -u [user] -p [passwd] Dism /online /Enable-Feature /FeatureName:smb1protocol /NoRestart /ALL
wmic /node:[IP] /user:[user] /password:[passwd] process call create "shutdown -r -f -t 0"
  1. 另一种可能的原因是防火墙

可以查看目前网络配置文件是公用还是专用。如果是公用,进一步查看是否开启了公用网络的防火墙

可以考虑直接切换到专用,关闭或配置专用网络的防火墙规则

本机上的system32目录内容与winexe cmd.exe dir出来的不一致

这是一个32-bit/64-bit问题

winexe新一点的版本会有[–ostype=0|1|2]选项,来指定x86/x64

可以通过echo %programfiles%看判断

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
C:\Windows\system32>echo %programfiles%
echo %programfiles%
C:\Program Files (x86)

C:\Windows\system32>dir nv*

2020/10/13 16:40 5,972,824 nvapi.dll
2020/10/13 16:42 4,174,064 nvcuda.dll
2020/10/13 16:42 6,860,184 nvcuvid.dll
2020/10/13 16:42 657,304 nvEncodeAPI.dll
2020/10/13 16:42 1,585,560 NvFBC.dll
2020/10/13 16:43 1,161,112 NvIFR.dll
2020/10/13 16:43 555,248 NvIFROpenGL.dll
2020/10/13 16:43 543,128 nvofapi.dll
8 21,509,424
0 ¼ 55,284,584,448

这里%programfiles%会被认为是 (x86)

没有nvidia-smi.exe

我们可以直接拉"c:\windows\sysnative\cmd.exe"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
C:\Windows\system32>echo %programfiles%
echo %programfiles%
C:\Program Files

C:\Windows\system32>dir nv*

2020/10/13 16:41 7,001,536 nvapi64.dll
2020/10/13 16:42 5,519,600 nvcpl.dll
2020/10/13 16:42 2,508,528 nvcuda.dll
2020/10/13 16:42 7,707,544 nvcuvid.dll
2020/10/13 16:42 445,848 nvdebugdump.exe
2020/10/13 16:42 813,464 nvEncodeAPI64.dll
2020/10/13 16:43 2,098,072 NvFBC64.dll
2020/10/13 16:43 589,208 nvidia-smi.exe
2020/10/13 16:43 1,507,224 NvIFR64.dll
2020/10/13 16:43 670,616 NvIFROpenGL.dll
2020/10/01 15:14 80,930 nvinfo.pb
2020/10/13 16:43 816,368 nvmcumd.dll
2020/10/13 16:43 1,023,216 nvml.dll
2020/10/13 16:43 673,520 nvofapi64.dll
14 31,455,674
0 ¼ 55,284,584,448

这样就正常了

参考 https://ss64.com/nt/syntax-64bit.html

LD 找不到 -l问题的统一解决

/usr/bin/ld: cannot find -l
collect2: error: ld returned 1 exit status

1
ld -l<xxx> --verbose

/usr/bin/ld: cannot find -lhdb

1
2
3
4
5
6
7
8
9
ld -lhdb --verbose
...
attempt to open /usr/lib64/libhdb.so failed
attempt to open /usr/lib64/libhdb.a failed
attempt to open /usr/local/lib64/libhdb.so failed
attempt to open /usr/local/lib64/libhdb.a failed
attempt to open /lib64/libhdb.so failed
attempt to open /lib64/libhdb.a failed
...

可以看到ld在尝试从哪些地方寻找所需的文件

然后就方面通过文件名判断该安装什么包或者做软连接

1
2
3
4
5
6
locate libhdb
/usr/lib64/heimdal/libhdb.a
/usr/lib64/heimdal/libhdb.so
/usr/lib64/heimdal/libhdb.so.9
/usr/lib64/heimdal/libhdb.so.9.2.0
ln -s /usr/lib64/heimdal/libhdb.so /usr/lib64/libhdb.so

参考代码:https://github.com/HBSpy/music163

FLAC to ALAC

1
ffmpeg -i input.flac -acodec alac -vn output.m4a

从云音乐获取的FLAC有时封面会有问题

1
2
3
4
5
6
7
8
9
[mjpeg @ 0x227f2c0] bits 223 is invalid
[flac @ 0x227c400] decoding for stream 1 failed
[flac @ 0x227c400] Could not find codec parameters for stream 1 (Video: mjpeg, none(bt470bg/unknown/unknown), lossless): unspecified size
Consider increasing the value for the 'analyzeduration' and 'probesize' options

...

Automatic encoder selection failed for output stream #0:0. Default encoder for format ipod (codec h264) is probably disabled. Please choose an encoder manually.
Error selecting an encoder for stream 0:0

这里使用-vn去掉封面图片,后续再通过其它方式添加

添加封面

封面图片获取

云音乐的FLAC备注中有163 key(Don’t modify):xxx,可以解密得出JSON

  • 算法: AES-128-ECB
  • KEY: #14ljk_!]&0U<'(

从albumPic字段获取封面图片地址

iTunes可识别的封入封面图片

到目前为止,直接使用ffmpeg封入封面,iTunes还是不能识别的

有给视频添加Cover的方式

1
ffmpeg -i input.m4a -i image.jpg -map 0 -map 1 -c copy -disposition:v:1 attached_pic output.m4a

但iTunes是识别不了的

目前使用AtomicParsley封入封面,https://github.com/wez/atomicparsley

1
./AtomicParsley output.m4a --artwork cover.jpg

–overWrite 参数有些编译版本似乎没有,手动重命名吧

我们记录,我们监控,我们管理

不做事,不BB

Problem

使用composer require 本地GitLab中的项目,会把.git文件夹一块拉进来,从而在commit的时候报子项目问题

Cause

在配置composer repositories时,type使用的是git,则在提取时,等同于git clone,则会连着.git一起clone下来

正确的方法应该是参考 https://docs.gitlab.com/ee/user/packages/composer_repository/

发布时

  1. 在项目中composer init 来生成composer.json
  2. 发布一个release或打一个tag
  3. 通过API发布Composer package,这一步需要access token

成功后会在项目的Package Registry的菜单下看到他

安装时

  1. 在Package Registry点详情进去也会看到相关命令
1
composer config repositories.<group_id> composer https://gitlab.example.com/api/v4/group/<group_id>/-/packages/composer/
  1. 需要设置access token,推荐–global,不然会在项目中留下auth.json,不宜提交
  2. 需要设置gitlab-domains
1
composer config gitlab-domains <你的GitLab地址>
  1. 如果你的GitLab是HTTP,还需要设置"secure-http": false
  2. composer require 你的包

对于Linux命令参数中被误解析成-xxx的参数问题,如

1
2
[root@HBSpy extreme]# rename -mib
rename: invalid option -- 'm'

可以在参数前加–

1
[root@HBSpy extreme]# rename -- -mib .mib extreme-*

参考: https://unix.stackexchange.com/questions/11376/what-does-double-dash-mean

More precisely, a double dash (–) is used in most bash built-in commands and many other commands to signify the end of command options, after which only positional arguments are accepted.
Example use: lets say you want to grep a file for the string -v - normally -v will be considered the option to reverse the matching meaning (only show lines that do not match), but with – you can grep for string -v like this:
grep – -v file

从CentOS-7-x86_64-Minimal编译安装Vim8

依赖

1
2
3
yum install python3 python3-devel
yum install ncurses ncurses-devel
yum install perl-devel perl-ExtUtils-Embed

configure参考

1
2
3
4
5
6
7
8
9
10
11
12
13
./configure --enable-pythoninterp=yes --enable-python3interp=yes --enable-multibyte --enable-luainterp=yes --enable-perlinterp=yes --enable-rubyinterp=yes --with-python3-command=python3 --enable-cscope

--with-features=TYPE tiny, small, normal, big or huge (default: huge)
# 默认就是huge了

--enable-python3interp=OPTS Include Python3 interpreter. default=no OPTS=no/yes/dynamic
# 这些interp根据说明应该是=yes

--with-python3-config-dir=PATH Python's config directory (deprecated)
# 这个已经deprecated了,改用--with-python3-command=python3

--enable-perlinterp=OPTS
# 启用就是事多,注意要装上面的依赖

make

1
2
3
4
cd src 			# 官方推荐你去src目录make
make distclean # if you build Vim before
make # 可以加-jN并行
sudo make install

XXX

enable了不等于装上了,之后最好vim --version查看下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
[root@localhost vim]# vim --version
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Feb 22 2021 14:47:31)
Included patches: 1-2541
Compiled by [email protected]
Huge version without GUI. Features included (+) or not (-):
+acl -farsi +mouse_sgr +tag_binary
+arabic +file_in_path -mouse_sysmouse -tag_old_static
+autocmd +find_in_path +mouse_urxvt -tag_any_white
+autochdir +float +mouse_xterm -tcl
-autoservername +folding +multi_byte +termguicolors
-balloon_eval -footer +multi_lang +terminal
+balloon_eval_term +fork() -mzscheme +terminfo
-browse +gettext +netbeans_intg +termresponse
++builtin_terms -hangul_input +num64 +textobjects
+byte_offset +iconv +packages +textprop
+channel +insert_expand +path_extra +timers
+cindent +ipv6 +perl +title
-clientserver +job +persistent_undo -toolbar
-clipboard +jumplist +popupwin +user_commands
+cmdline_compl +keymap +postscript +vartabs
+cmdline_hist +lambda +printer +vertsplit
+cmdline_info +langmap +profile +virtualedit
+comments +libcall -python +visual
+conceal +linebreak +python3 +visualextra
+cryptv +lispindent +quickfix +viminfo
+cscope +listcmds +reltime +vreplace
+cursorbind +localmap +rightleft +wildignore
+cursorshape -lua -ruby +wildmenu
+dialog_con +menu +scrollbind +windows
+diff +mksession +signs +writebackup
+digraphs +modify_fname +smartindent -X11
-dnd +mouse -sound -xfontset
-ebcdic -mouseshape +spell -xim
+emacs_tags +mouse_dec +startuptime -xpm
+eval -mouse_gpm +statusline -xsmp
+ex_extra -mouse_jsbterm -sun_workshop -xterm_clipboard
+extra_search +mouse_netterm +syntax -xterm_save

你看这个lua和ruby的interp其实就没装上

UI Recorder jWebDriver 不支持括号开头的XPath, 如

1
(//input)[2]

原因在于jWebDriver错误的认为括号开头的是css selector

修改lib/elements.js

1
2
// using = /^\.?\//.test(value)?'xpath':'css selector';
using = /^(\.|\()?\//.test(value)?'xpath':'css selector';

1
$input = shell_exec($cmd = '/usr/bin/python3 ' . APP_PATH . "/library/OpsKG/input_jieba.py $input");

无输出,python其实并没有收到正确的中文输入,exec的中文编码问题

需要先设置exec的环境变量

1
2
putenv('LC_ALL=en_US.UTF-8');
$input = shell_exec($cmd = '/usr/bin/python3 ' . APP_PATH . "/library/OpsKG/input_jieba.py $input");

或在命令前export LANG=en_US.UTF-8;

0%