(May-31-2024, 06:11 PM)snippsat Wrote: [ -> ] (May-31-2024, 05:36 PM)robertkwild Wrote: [ -> ]if its a security concern what other way do you recommend doing what i want to do
Not sure what task you trying to do.
It can be ok if check input and don't allow all command that can be given to Powershell.
Eg this would delete a local file or worse if do Remove-Item -Path C:/*.*
it start to delete all files on C:
import subprocess
new_password = 'Remove-Item -Path C:/bar/file-1.txt'
# Execute the PowerShell command
result = subprocess.run(["powershell", "-Command", new_password], capture_output=True, text=True)
So eg in previous post here f"Get-ChildItem -Path '{new_password}'"
it's restricted to only use Get-ChildItem -Path
.
Then cannot give full PS command that eg can delete files local from input in web-form.
im just going to get it to run a powershell command to change the users password ie
Set-ADAccountPassword -Identity username -OldPassword (ConvertTo-SecureString -AsPlainText "old_password" -Force) -NewPassword (ConvertTo-SecureString -AsPlainText "confirm" -Force) -Server domain
but im trying to do some validation but the equalto doesnt work and no idea why
from flask import Flask, render_template, request
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, BooleanField, DecimalField, RadioField, SelectField, TextAreaField, FileField, validators, SubmitField
from wtforms.validators import InputRequired, Length, DataRequired, EqualTo, Regexp, ValidationError
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secretkey'
class MyForm(FlaskForm):
username = StringField('Username', [InputRequired('Required')])
old_password = PasswordField('Old Password', [InputRequired('Required')])
password = PasswordField('New Password', [InputRequired('Required'), EqualTo('confirm', message='Passwords must match'), Length(min=12)])
confirm = PasswordField('Confirm New Password')
domain = SelectField('domain', choices=[('prod', 'prod'), ('corp', 'corp')])
submit = SubmitField('Submit')
@app.route('/', methods=['GET', 'POST'])
def index():
form = MyForm()
if form.validate_on_submit():
username = form.username.data
old_password = form.old_password.data
password = form.password.data
confirm = form.confirm.data
domain = form.domain.data
submit = form.submit.data
return render_template('index.html', form=form)
if __name__ == '__main__':
app.run()