paolo

Net Share Commands

We can use net share command to create, configure and delete network shares from command line . Below you can find syntax and examples for net share command.

Create a network share from command line

The syntax for creating a share is as follows.

net share sharename=folderpath /grant:username,permissions

sharename: You can assign name to the share you are going to create
username : Login id of the user whom you want to share the folder with
permission: Read, Change or Full

For example to share the folder E:\Docs with everyone in the domain and to give full permissions

net share Docs=E:\Documents /grant:everyone,FULL

If you are allowing multiple users to access the share, you can limit the number of users accessing the share simultaneously. This will prevent performance impact on your system. The below command will set the limit to 10 users.

net share Docs=E:\Documents /grant:everyone,FULL  /users:10

Command to share with a specific user and to grant only read rights:

net share Docs=E:\Documents /grant:username,READ

Delete network share(i.e to disable sharing of the folder) from command line

net share sharename /delete

For example, to delete the share created above, the command would be as below.

net share docs /delete

Alternatively, we can use the folder physical location also to disable sharing

 net share E:\Docs /delete

List the shared created on the local computer

net share

Delete the share on a remote computer

net share sharename \\remotepc /delete

check time with powershell


function Get-MyDate{
[CmdletBinding()]
param(
[Parameter(Mandatory=$True,
ValueFromPipeLine=$True,
ValueFromPipeLineByPropertyName=$True,
HelpMessage="ComputerName or IP Address to query via WMI")]
[string[]]$ComputerName
)

foreach($computer in $computerName){
$timeZone=Get-WmiObject -Class win32_timezone -ComputerName $computer
$localTime = Get-WmiObject -Class win32_localtime -ComputerName $computer
$output =@{'ComputerName' = $localTime.__SERVER;
'Current Time' = (Get-Date -Day $localTime.Day -Month $localTime.Month);
}
$object = New-Object -TypeName PSObject -Property $output
Write-Output $object
}
}

get-mydate -ComputerName MyComputerName

Debian 9 as a Veeam backup destination over SSH

Clean installation of a Debian 9.
install required packages:
– openssh-server
– libsoap-lite-perl

How to mount a physical crypted disk on another debian 9 system:

apt-get install cryptsetup
apt-get install lvm2
--
lvscan
lvscan vgchange -ay
lvscan --help
lvscan
mount /dev/mapper/luks-9a9a7076-a9e3-4393-8132-bd0ee666d171 /mnt
sudo fdisk -l
fdisk -l
udisksctl unlock -b /dev/sdb5
mount /dev/dm-0 /mnt
vgchange -ay
lvscan
mount /dev/backup2-vg/root /mnt
cd /mnt/veeam_backup/
--
fdisk -l
lvscan
udisksctl unlock -b /dev/sdb5
vgchange -ay
mount /dev/dm-0 /mnt
mount /dev/backup2-vg/root /mnt
cd /mnt/veeam_backup/

How to mount a VMDK (crypted) disk on another debian 9 system:

kpartx -av .vmdk --> crea /dev/mapper/loop0p1 
lvscan
vgchange -ay
udisksctl unlock -b /dev/mapper/loop0p5
lvscan
mount /dev/backup3-vg/root /mnt   ---(o il nome della partizione /root cifrata)---

Best Exchange ActiveSync Mail Apps for AndroidForWork

Today we’ll talk about Exchange ActiveSync Mail Apps for AndroidForWork environment.

In my company we use Blackberry UEM 12.6 as MDM platfrom; with the new functionalities of Android For Work we can enable only some apps for the Play Store and block all the other ones.

As Mail apps we tested Blackberry Hub, Outlook by Microsoft, BlueMail by Blue Mail Inc, Email Exchange by MailWise and Vmware Boxer on mainly Samsung S7 devices.

Here some considerations and at the end the definitive choice.

Blackberry Hub

PROS:

  • Good integration with the UEM Environment
  • Good Support for Exchange/ActiveSync
  • Receive settings and configurations from UEM

CONS:

  • not working with hybrid configuration of Exchange and office 365
  • Free only for 30 days and purchasable only by single user, not via B2B channel

Outlook

PROS:

  • Very good support of Exchange and Office 365 connections; quick, clean and essential app.
  • completely free and without advertising

CONS:

  • no integration with the system calendar and partially with the address book (in-app option to sync contacts but a lot of problems for searching into Company Exchange Global Address List)
  • No week-view into integrated Calendar
  • Very slow sync for mail and calendar events (even 30 minutes late!!)

BlueMail

PROS:

  • Good support of Exchange and Office365 (but only with thirdy-part provided ActiveSync component)
  • Perfect sync with the company GAL
  • Perfect sync with the Calendar
  • Completely free and without advertising

CONS:

  • Without the default Android e-mail client and without another app that wake up the ActiveSync feature BlueMail cannot manage ActiveSync accounts.

VmWare Boxer

PROS:

  • Good support of Exchange and Office365
  • Perfect sync with the company GAL
  • Perfect sync with the Calendar
  • Completely free and without advertising

CONS:

  • some minor features outlook-desktop style are missing

MailWise

PROS:

  • Good support of Exchange and Office365
  • Perfect sync with the company GAL
  • Perfect sync with the Calendar

CONS:

  • the free version of the app requests upgrade to pro version for 2.99$.

Conclusion

At the end of the tests we decided to use VmWare Boxer as default mail/calendar/address book client for Android because of the limits and lacks of the other apps.

In the future we hope that Blackberry could resolve the license issues and the office 365 (also in hybrid configuration) support for its Android suite apps because this could effort security, limitations and control on the users accounts.

 

Crack password on an Excel VBA Project

Please backup your files first!

Open the file(s) that contain your locked VBA Projects

Create a new xlsm file and store this code in Module1

code credited to Siwtom (nick name), a Vietnamese developer

Option Explicit
Private Const PAGE_EXECUTE_READWRITE = &H40
Private Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" _
            (Destination As Long, Source As Long, ByVal Length As Long)
Private Declare Function VirtualProtect Lib "kernel32" (lpAddress As Long, _
    ByVal dwSize As Long, ByVal flNewProtect As Long, lpflOldProtect As Long) As Long
Private Declare Function GetModuleHandleA Lib "kernel32" (ByVal lpModuleName As String) As Long

Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, _
            ByVal lpProcName As String) As Long

Private Declare Function DialogBoxParam Lib "user32" Alias "DialogBoxParamA" (ByVal hInstance As Long, _
            ByVal pTemplateName As Long, ByVal hWndParent As Long, _
            ByVal lpDialogFunc As Long, ByVal dwInitParam As Long) As Integer

    Dim HookBytes(0 To 5) As Byte
    Dim OriginBytes(0 To 5) As Byte
    Dim pFunc As Long
    Dim Flag As Boolean

    Private Function GetPtr(ByVal Value As Long) As Long
        GetPtr = Value
    End Function

    Public Sub RecoverBytes()
        If Flag Then MoveMemory ByVal pFunc, ByVal VarPtr(OriginBytes(0)), 6
    End Sub

    Public Function Hook() As Boolean
        Dim TmpBytes(0 To 5) As Byte
        Dim p As Long
        Dim OriginProtect As Long

        Hook = False

        pFunc = GetProcAddress(GetModuleHandleA("user32.dll"), "DialogBoxParamA")


        If VirtualProtect(ByVal pFunc, 6, PAGE_EXECUTE_READWRITE, OriginProtect) <> 0 Then

            MoveMemory ByVal VarPtr(TmpBytes(0)), ByVal pFunc, 6
            If TmpBytes(0) <> &H68 Then

                MoveMemory ByVal VarPtr(OriginBytes(0)), ByVal pFunc, 6

                p = GetPtr(AddressOf MyDialogBoxParam)

                HookBytes(0) = &H68
                MoveMemory ByVal VarPtr(HookBytes(1)), ByVal VarPtr(p), 4
                HookBytes(5) = &HC3

                MoveMemory ByVal pFunc, ByVal VarPtr(HookBytes(0)), 6
                Flag = True
                Hook = True
            End If
        End If
    End Function

    Private Function MyDialogBoxParam(ByVal hInstance As Long, _
            ByVal pTemplateName As Long, ByVal hWndParent As Long, _
            ByVal lpDialogFunc As Long, ByVal dwInitParam As Long) As Integer
        If pTemplateName = 4070 Then
            MyDialogBoxParam = 1
        Else
            RecoverBytes
            MyDialogBoxParam = DialogBoxParam(hInstance, pTemplateName, _
                               hWndParent, lpDialogFunc, dwInitParam)
            Hook
        End If
    End Function

Paste this code under the above code in Module1 and run it

    Sub unprotected()
        If Hook Then
            MsgBox "VBA Project is unprotected!", vbInformation, "*****"
        End If
    End Sub

Come back to your VBA Projects and enjoy.

how to know what type of object we handle with powershell

This simple powershell script returns True o False if our object is of the same specified type or not.

<# $object contains my username string #>
$object="MyUser"
<# $type contains the type string (User or Group or Computer or OU) #>
$type="User" 

$seek = [System.DirectoryServices.DirectorySearcher]"LDAP://dc=contoso,dc=com"
$seek.Filter = “(&(name=$object)(objectCategory=$type))”
 
Write-Host($seek.FindOne() -ne $null)

how to send html e-mails with php

This is a simple script for sending an html formatted e-mail:

$subject = "My Subject";

$headers = "From: paolo@pizzolongo.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

$message = <<< EOT
< html >
< head >
< style >
body{background-color:#eee;margin:0;padding:0;border:0;}
h1{background-color:black;color:white;border-bottom:2px solid red;
font-size:16px; font-family:Arial;height:30px;line-height:30px;
text-indent:10px;vertical-align:middle;}
p{font-size:13px;font-family:Arial;line-height:1.2em;}


< body >
< h1 >Example Text< /h1 >
 

Hello,
this is a little text example.
Paolo's web site
regards


EOT;

mail($send_to,$subject,$message,$headers);


Hot to get shared folders permissions with a powershell script

with this powershell script we’ll be able to get share permissions and ntfs permissions form all the shares of our servers list.

Function GetSharedFolderPermission($ComputerName)
{
	#test server connectivity
	$PingResult = Test-Connection -ComputerName $ComputerName -Count 1 -Quiet
	if($PingResult)
	{
		#check the credential whether trigger
		if($Credential)
		{
			$SharedFolderSecs = Get-WmiObject -Class Win32_LogicalShareSecuritySetting `
			-ComputerName $ComputerName -Credential $Credential -ErrorAction SilentlyContinue
		}
		else
		{
			$SharedFolderSecs = Get-WmiObject -Class Win32_LogicalShareSecuritySetting `
			-ComputerName $ComputerName -ErrorAction SilentlyContinue
		}
		
		foreach ($SharedFolderSec in $SharedFolderSecs) 
		{ 
		    $Objs = @() #define the empty array
			
	        $SecDescriptor = $SharedFolderSec.GetSecurityDescriptor()
	        foreach($DACL in $SecDescriptor.Descriptor.DACL)
			{  
				$DACLDomain = $DACL.Trustee.Domain
				$DACLName = $DACL.Trustee.Name
				if($DACLDomain -ne $null)
				{
	           		$UserName = "$DACLDomain\$DACLName"
				}
				else
				{
					$UserName = "$DACLName"
				}
				
				#customize the property
				$Properties = @{'ComputerName' = $ComputerName
								'SharedFolderName' = $SharedFolderSec.Name
								'SecurityPrincipal' = $UserName
								'FileSystemRights' = [Security.AccessControl.FileSystemRights]`
								$($DACL.AccessMask -as [Security.AccessControl.FileSystemRights])
                                'NTFS' = 0}
				$SharedACLs = New-Object -TypeName PSObject -Property $Properties
				$Objs += $SharedACLs

	        }
			$Objs|Select-Object ComputerName,SharedFolderName,SecurityPrincipal,FileSystemRights,NTFS
	    }  
	}
	else
	{
		$Properties = @{'ComputerName' = $ComputerName
						'SharedFolderName' = "Not Available"
						'SecurityPrincipal' = "Not Available"
						'FileSystemRights' = "Not Available"
                        'NTFS' = 0}
		$SharedACLs = New-Object -TypeName PSObject -Property $Properties
		$Objs += $SharedACLs
		$Objs|Select-Object ComputerName,SharedFolderName,SecurityPrincipal,FileSystemRights,NTFS
	}
}

Function GetSharedFolderNTFSPermission($ComputerName)
{
	#test server connectivity
	$PingResult = Test-Connection -ComputerName $ComputerName -Count 1 -Quiet
	if($PingResult)
	{
		#check the credential whether trigger
		if($Credential)
		{
			$SharedFolders = Get-WmiObject -Class Win32_Share `
			-ComputerName $ComputerName -Credential $Credential -ErrorAction SilentlyContinue
		}
		else
		{
			$SharedFolders = Get-WmiObject -Class Win32_Share `
			-ComputerName $ComputerName -ErrorAction SilentlyContinue
		}

		foreach($SharedFolder in $SharedFolders)
		{
			$Objs = @()
			
			$SharedFolderPath = [regex]::Escape($SharedFolder.Path)
			if($Credential)
			{	
				$SharedNTFSSecs = Get-WmiObject -Class Win32_LogicalFileSecuritySetting `
				-Filter "Path='$SharedFolderPath'" -ComputerName $ComputerName  -Credential $Credential
			}
			else
			{
				$SharedNTFSSecs = Get-WmiObject -Class Win32_LogicalFileSecuritySetting `
				-Filter "Path='$SharedFolderPath'" -ComputerName $ComputerName
			}
			
			$SecDescriptor = $SharedNTFSSecs.GetSecurityDescriptor()
			foreach($DACL in $SecDescriptor.Descriptor.DACL)
			{  
				$DACLDomain = $DACL.Trustee.Domain
				$DACLName = $DACL.Trustee.Name
				if($DACLDomain -ne $null)
				{
	           		$UserName = "$DACLDomain\$DACLName"
				}
				else
				{
					$UserName = "$DACLName"
				}
				
				#customize the property
				$Properties = @{'ComputerName' = $ComputerName
								'SharedFolderName' = $SharedFolder.Name
								'SecurityPrincipal' = $UserName
								'FileSystemRights' = [Security.AccessControl.FileSystemRights]`
								$($DACL.AccessMask -as [Security.AccessControl.FileSystemRights])
								'NTFS' = 1}
								
				$SharedNTFSACL = New-Object -TypeName PSObject -Property $Properties
	            $Objs += $SharedNTFSACL
	        }
			$Objs |Select-Object ComputerName,SharedFolderName,SecurityPrincipal,FileSystemRights,NTFS -Unique
		}
	}
	else
	{
		$Properties = @{'ComputerName' = $ComputerName
						'SharedFolderName' = "Not Available"
						'SecurityPrincipal' = "Not Available"
						'FileSystemRights' = "Not Available"
						'NTFS' = "1"}
					
		$SharedNTFSACL = New-Object -TypeName PSObject -Property $Properties
	    $Objs += $SharedNTFSACL
		$Objs |Select-Object ComputerName,SharedFolderName,SecurityPrincipal,FileSystemRights,NTFS -Unique
	}
} 

Function LetsStart($ComputerName){
	foreach($CN in $ComputerName){
			GetSharedFolderNTFSPermission -ComputerName $CN
			GetSharedFolderPermission -ComputerName $CN
	}
}

$ComputerName="server01","server02","server03"
$CurrentDate = Get-Date
$CurrentDate = $CurrentDate.ToString('yyyy-MM-dd_HH-mm')

LetsStart($ComputerName) | Export-Csv “c:\path\to\file\$CurrentDate.csv" -NoTypeInformation